Warn if `#' is preceded by whitespace?
Kaveh R. Ghazi
ghazi@caip.rutgers.edu
Wed Feb 16 09:48:00 GMT 2000
> From: Zack Weinberg <zack@wolery.cumb.org>
>
> On Wed, Feb 16, 2000 at 04:47:54AM -0200, Alexandre Oliva wrote:
> > Wouldn't it be a good idea to emit a warning when the `#' of a CPP
> > directive is not in the beginning of the line?
>
> Certainly not with no way to turn it off! It's explicitly
> permitted by C89, and I've seen it used deliberately to hide
> directives from K+R preprocessors.
Yes, e.g. SunOS4 cc doesn't understand #error, so you have to write it
like this:
#if condition
#error "foo"
#endif
if you write
#if condition
#error "foo"
#endif
then you'll get "undefined control" even if the "condition" doesn't
trigger.
> I'd suggest -Wtraditional only (which cpp doesn't know about right
> now, but that can easily change).
> zw
If we go with -Wtraditional, whose purpose is to make programs more
portable to traditional C, we should warn about whitespace preceeding
things like #if, #else and #endif, but warn about *missing* whitespace
in front of #error. (We'll have to decide for any other directives
too whether they are traditional C or ANSI C directives and what to do
with each one.) I.e. we might also want to warn about any uses at all
of e.g. #elif with -Wtraditional.
--Kaveh
--
Kaveh R. Ghazi Engagement Manager / Project Services
ghazi@caip.rutgers.edu Qwest Internet Solutions
More information about the Gcc-patches
mailing list