4

We had been using some directives in our code that are invalid in today's standards. eg. #COMMENT1

This used to work in very old version of gcc (2.x). I'm trying to move it off to new gcc (4.x) however I'm getting errors such as : "error: invalid preprocessing directive #COMMENT1"

Easy fix is to change # to // in those directives, but we cannot do that due to some other dependencies.

Question is, is there a way to tell cpp to ignore these invalid directives ?

However it should interpret the valid directives as it should eg #ifndef #define etc

Thank you!

user406481
  • 145
  • 2
  • 6

3 Answers3

2

You didn't say why you

cannot change # to // in those directives

I guess you have some tools or scripts depending on them. You should update these to follow the current standard.

Maybe a more unique or improbable suffix might help you, eg use //#COMMENT instead of #COMMENT

But essentially, you are asking a more or less standard conforming compiler to understand a non-standard and deprecated language feature, and that is essentially hopeless.

Alternatively, you could patch a recent GCC source code (e.g. GCC 4.6 one) to follow your requirements, but I don't think it is a very good idea (and even the plugin ability of GCC 4.6 don't help here, since there are no plugin hooks for that in its preprocessor).

My advice is still to change your source code to be more conformant to current standards. This is almost never a time loss to do so.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
0

I was getting those errors (g++ 4.5.4) because the pre-processor keywords were case sensitive.

#DEFINE _HEADER_FILE_
#ENDIF

would fail whereas

#define _HEADER_FILE_
#endif

would pass. Basile said it well though. It would be worth your while to catch up on the more recent compiler standard.

NuclearPeon
  • 5,743
  • 4
  • 44
  • 52
0

On linux cpp has a flag to try to emulate the traditional C style pre-processor

From the cpp man page:

-traditional-cpp 

   Try to imitate the behavior of old-fashioned C preprocessors, as opposed to ISO C preprocessors.
Yelbam
  • 1