Re: Could -Wall add on -Wundef by default ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 2 Mar 2019 at 17:15, David Brown <david@xxxxxxxxxxxxxxx> wrote:
>
>
>
> On 02/03/2019 14:46, Jonathan Wakely wrote:
> > On Sat, 2 Mar 2019 at 13:42, Jonny Grant wrote:
> >>>> Perhaps just adding to -Wextra would make sense?
> >>>
> >>> I would still be strongly against that. Why can't you just use
> >>> -Wundef, instead of forcing everybody else to change their code to
> >>> follow your preferred convention?
> >>
> >> Yes, we use it. Presumably someone decided what should go into -Wextra,
> >> and presumably it is things that are worth adding... in my view it's
> >> worth adding. No worries if that isn't consensus though! :)
> >
> > -Wundef is only useful if your code always does:
> >
> > #if defined(MACRO) && MACRO
> >
> > instead of just #if MACRO.
> >
> > They are both perfectly valid ways to write your code. People who are
> > happy to write the latter should not have to deal with warnings that
> > are only useful to people who write the former.
> >
>
> Actually, I think the way to use -Wundef is to write your code:
>
> #define enable_feature_X 1
> #define enable_feature_Y 0
>
> #if enable_feature_X
> ...
> #endif
>
> #if enable_feature_Y
> ...
> #endif
>
>
> I use -Wundef in my own code, and only ever make use of "defined" or
> "#ifdef" if it is a predefined macro, something from third-party code,
> or a define I expect to get from the command line.  To me, it is vital
> to write:
>
>         #define enable_feature_Y 0
>
> to show that this is an option that is available, but I am specifically
> choosing not to use it.
>
> -Wundef helps enforce this and avoids mystical options that come from
> nowhere or having things that /could/ be usefully enabled if only the
> user knew about them.

Yes, that's how glibc does it too.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux