Ignore invalid directives in cpp

We used some directives in our code that are not valid in today's standards. eg. # COMMENT1

This was used to work in a very old version of gcc (2.x). I am trying to move it to the new gcc (4.x), however I get errors such as: "error: invalid preprocessing directive # COMMENT1"

A simple fix is ​​to change # to // in these directives, but we cannot do this due to some other dependencies.

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

However, it must interpret valid directives as it should be, for example: #ifndef #define, etc.

Thanks!

+4
source share
3 answers

You did not say why you

cannot change # to // in these directives

I think you have tools or scripts depending on them. You must update them to follow the current standard.

Perhaps a more unique or incredible suffix can help you, for example, use //#COMMENT instead of #COMMENT

But, in essence, you are asking a more or less standard matching compiler to understand a non-standard and outdated language function, and this is essentially hopeless.

Alternatively, you can fix the recent GCC source code (e.g. GCC 4.6) to fit your requirements, but I don't think it is a very good idea (and even GCC 4.6 plugins do not help here, since there are no hook plugins in its preprocessor )

My advice, as before, is to change the source code to meet current standards. This almost never leads to a loss of time.

+2
source

I was getting these errors (g ++ 4.5.4) because the preprocessor keywords were case sensitive.

 #DEFINE _HEADER_FILE_ #ENDIF 

does not work, whereas

 #DEFINE _HEADER_FILE_ #ENDIF 

will pass. Basil said it well. It would be wise to catch up with the later compiler standard.

0
source

Linux cpp has a flag to try to emulate a traditional C style preprocessor

On the cpp man page:

 -traditional-cpp Try to imitate the behavior of old-fashioned C preprocessors, as opposed to ISO C preprocessors. 
0
source

All Articles