Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

like image 789
abligh Avatar asked Jan 06 '23 06:01

abligh


2 Answers

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.

like image 168
nalzok Avatar answered Jan 15 '23 09:01

nalzok


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.

like image 39
Stephen C Avatar answered Jan 15 '23 08:01

Stephen C