Search code examples
cstructcompiler-warningssuppress-warnings

Resolve build warning - "extra tokens at end of #include directive"


I am testing a solution I tried in a previous question: Use typedef within struct for naming and indexing text commands

However, I would like to keep my compiler warnings to none. I use static code analysis tools for this purpose, and in the case of certain tools (ie: LINT) I can manually exclude certain rules and warnings on a per-line basis using markup within my comments.

In the case of the first/top answer, I tried that solution, but modified the final structure to look like so:

struct command commands[] =
{
#include "commands.inc",
{NULL, NULL}
};

This is so I can know if, during a search, that I've reach the largest addressable member of this array-of-struct and not get an out-of-bounds condition. The problem is that I know have a compiler warning, "Warning: extra tokens at end of #include directive". Is there any way to disable this warning? I like this solution, and it suits my needs very well.



In the end, I updated my .inc file to be like so:

CMD(list),
CMD(quit),
CMD(start),

instead of

CMD(list),
CMD(quit),
CMD(start)

I then was able to remove the trailing commas from both my macro definitions and from my static initialization code.


Solution

  • You should remove the comma at the end of your #include directive. It should not be there.