abligh
abligh

Reputation: 25169

C standard prohibition on warnings by default

Seeing yet another question the answer to which would have been obvious had the questioner compiled with -Wall got me thinking.

Is there a 'C standard' based reason why -Wall cannot be enabled by default by the compiler?

As far as I know none of the major compilers do this (and certainly historically none of them did it), and I'd like to know whether this is adherence to the standard, or some other reason (inertia, back compatibility or whatever). Speculating as to the other reason is probably off-topic (opinion based), but I think asking whether a standard requires this behaviour is on-topic (factual).

Upvotes: 4

Views: 195

Answers (3)

fluter
fluter

Reputation: 13826

Besides the reason mentioned above, that the standard does not have specifications on warnings, make Wall default would be more a obstacle for many people because there are warnings that you actually don't want to turn on from time to time, such as warnings on unused variables/functions etc. If you want to make it "by default", you can alias the compiler of your choice, take gcc as example, add following in your bashrc:

alias gcc="gcc -Wall"

Upvotes: 0

nalzok
nalzok

Reputation: 16127

Quoted from N1570 Annex I:

1 An implementation may generate warnings in many situations, none of which are specified as part of this International Standard.

This implies that warnings are non-compulsory to compilers, so I don't think there would be any "C standard" based reasons.

Upvotes: 5

Stephen C
Stephen C

Reputation: 719279

Is there a 'C standard' based reason why -Wall cannot be enabled by default by the compiler?

I think that the answer to that is that no standard-based reason. The behavior of compiler switches is outside the scope of a language standard.

Beyond that, a compiler is (generally speaking) not required to produce diagnostics for things that are not specified to be compilation errors, so requiring such diagnostics be output "by default" is nonsensical.


And to be clear, these general statements apply in the case of the C language.

Upvotes: 4

Related Questions