15

Is is possible to put something at the top of the C source file, like

// GCC_OPTIONS=-g,-Wall

that will add those options automatically to gcc every time you compile this file?

2 Answers 2

12

Yes it is, at least for some flags. You can push and pop diagnostic settings like this:

#pragma GCC diagnostic error "-pedantic"
#pragma GCC diagnostic warning "-Wall"

This is also possible for optimization levels on a per-function level:

#pragma GCC optimize ("string"...)

These #pragma definitions affect all code after them in a source file.

See these other questions for more information:

Sign up to request clarification or add additional context in comments.

4 Comments

Neither of these are equivalent to the options he's asking about.
@MatthewFlaschen These settings affect all functions defined later in a source file, so to some extent they can be equivalent: put them on the top and they kind of become global.
No debug unfortunately it seems: stackoverflow.com/questions/2006821/…
Is there a pragma for setting an -f/-fno flag (e.g., ` -fno-ipa-icf`)?
1

No. Some compiler options have #define equivalents, but not those. This belongs in your make file (or equivalent). With GNU Make:

CFLAGS += -g -Wall

2 Comments

-Wall has an in source equivalent.
@Matt, what is it? Your answer doesn't give one, and #pragma GCC diagnostic warning "-Wall" definitely doesn't work in GCC 4.4.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.