Pregunta

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 have 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).

¿Fue útil?

Solución

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

  1. Correct them all to one consistent casing
  2. 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.

Otros consejos

Have you tried using the entry command:

  subroutine name1 (args)
  entry      name2 (args)
  entry      name3 (args)
  ....
  return
  end
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top