Case insensitive #define
Is it possible to issue a case insensitive #define statement with the preprocessor?
For example, I want to convert any casing of foobar to spameggs, i.e.:
FooBar -> spameggs
foobar -> spameggs
fooBar -> spameggs
Foobar -> spameggs
FOOBAR -> spameggs
FOOBAr -> spameggs (an odd possibility I know)
etc
The reason behind this is that I want to #define some fortran subroutines to ha开发者_JAVA技巧ve different names, and they of course are case insensitive. Please note that I don't really care about preserving the capitalisation scheme (which in the last example seems kinda nonsense).
Alas, as you know, C identifiers are case sensitive. Hence, so are pre-processor symbols (if one were case sensitive and the other were not, you could get some very strange behaviours when you intended to alter just one of the symbols with the preprocessor). There isn't an override flag for this behaviour, nor an alternative define
construct (at least that I'm aware of in GCC compiler front-ends for C/++).
The most obvious solution will be to grep
your code for foobar
, case insensitively. Use the results to build a table of all possible foobar casings and either
- Correct them all to one consistent casing
- Create a single pre-processor file that does the redefinitions for all the cases.
In the later solution, you needn't pollute some human readable code with this - just machine generate a FixFooBar.h
file full of these remappings, and include it where needed.
Have you tried using the entry command:
subroutine name1 (args)
entry name2 (args)
entry name3 (args)
....
return
end
精彩评论