Suppress GCC warning “extra tokens at end of #incl

2019-07-18 05:23发布

问题:

I'm writing a program in C intended to be compiled and run on a HP NonStop machine. However, I want to do the main development on my workstation running Linux. The HP NonStop C-Compiler requires non-standard #include directives like the following:

#include <stdio.h> nolist

For each #include directive, my workstation's GCC is complaining:

S88USF.c:139:21: warning: extra tokens at end of #include directive

How can I suppress this particular warning?

Note: On SO, similar questions have already been asked, the correct answer being along the lines of "don't give gcc any reason to complain in the first place". In this scenario however, I explicitly want to have the #include directives exactly as they are.

I know what I'm doing, I just don't know how to inform gcc about it.

回答1:

Macroexpansion happening within include can probably help.

GCC will accept this:

#define nolist
#include <stdlib.h> nolist
/* maybe #undef nolist here */


回答2:

One workaround would be to define a header that includes the following preproccesor macro:

//hp_workaround.h
#ifdef HP_
#define HP_INCLUDE_DIRECTIVE(x) x
#else
#define HP_INCLUDE_DIRECTIVE(x) 
#endif

then guard your directives with this macro

#include "hp_workaround.h"
#include <stdio.h> HP_INCLUDE_DIRECTIVE(nolist)