On 03/03/2019 00:15, David Brown 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.
But that is /my/ choice for the way I like to code - other people choose
differently, so I happily add -Wundef to my own makefiles and let others
do something different. And if I want to enforce such things for code I
write, there are always gcc diagnostic pragmas.
There are a lot of warnings that gcc provides, and I use many of them
beyond the common -Wall -Wextra. But I think it would be impossible to
agree on sets that would suit people - the choice of suitable warnings
is too varies by person and project.
.
Fair enough. I also follow your approach. It's easy enough to add
-Wundef to makefiles.
Cheers, Jonny