3

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.

Philip
  • 5,795
  • 3
  • 33
  • 68
  • possible duplicate of [disable specific warnings in gcc](http://stackoverflow.com/questions/1079997/disable-specific-warnings-in-gcc) – Vicky Jan 11 '13 at 14:58
  • I've voted to close as duplicate - there are indeed lots of questions already on SO with this scenario including specific answers about how to suppress the warnings, not just "don't give gcc any reason to complain in the first place". – Vicky Jan 11 '13 at 14:59
  • possible duplicate of [How to supress specific warnings in g++](http://stackoverflow.com/questions/487108/how-to-supress-specific-warnings-in-g) – Jonathan Leffler Jan 13 '13 at 07:43
  • The other questions deal with switching warnings on and off via the `-Wblah` family of flags, which are inapplicable in this case according to the [GNU CPP Manual](https://gcc.gnu.org/onlinedocs/cpp/Invocation.html#Invocation) under the description of `cpp`'s `-Wall` option: "Note that many of the preprocessor's warnings are on by default and have no options to control them." So, this isn't a duplicate after all. – LThode Nov 05 '14 at 20:49
  • 2
    I came upon this question after answering answering a somewhat related question [here](http://stackoverflow.com/q/27817081/1708801). If you can use `clang` instead as far as I can tell it supports `-Wno-extra-tokens` which would be a clean solution. – Shafik Yaghmour Jan 07 '15 at 13:48

2 Answers2

8

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)
netcoder
  • 66,435
  • 19
  • 125
  • 142
cmh
  • 10,612
  • 5
  • 30
  • 40
2

Macroexpansion happening within include can probably help.

GCC will accept this:

#define nolist
#include <stdlib.h> nolist
/* maybe #undef nolist here */
Anton Kovalenko
  • 20,999
  • 2
  • 37
  • 69
  • I would have preferred disabling the GCC warning by using something like `-Wsuppress-extra-tokens-warning`, but this solution seemingly is the next best thing. Thanks! – Philip Jan 11 '13 at 15:08