This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] moving macro definitions to defaults.h
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Andrew MacLeod <amacleod at redhat dot com>
- Cc: gcc-patches <gcc-patches at gcc dot gnu dot org>, Richard Biener <richard dot guenther at gmail dot com>
- Date: Mon, 22 Sep 2014 17:02:19 +0000
- Subject: Re: [patch] moving macro definitions to defaults.h
- Authentication-results: sourceware.org; auth=none
- References: <54204DA9 dot 1050802 at redhat dot com>
On Mon, 22 Sep 2014, Andrew MacLeod wrote:
> Josephs solution was to identify these and instead put a default definition in
> default.h ... then change all the uses to #if instead.. ie,
> #if BLAH
>
> This way we can ensure that the definition has been seen and it will be a
> compile error if not.
No, my suggestion was that whenever possible we should change preprocessor
conditionals - #ifdef or #if - into C conditionals - "if (MACRO)".
Changing from #ifdef to #if does nothing to make a missing tm.h include
produce an error - the undefined macro simply quietly gets treated as 0 in
preprocessor conditionals. To get an error from #if in such cases, you'd
need to build GCC with -Wundef (together with existing -Werror), and I'd
guess there are plenty of places that are not -Wundef clean at present.
Now, I think moves of defaults to defaults.h are generally a good idea,
and that moving from defined/undefined to true/false semantics are also a
good idea - even if the way the macro is used means you can't take the
further step of converting from #if to if (). They don't solve the
problem of making a missing tm.h include immediately visible, but they
*do* potentially help with future automatic refactoring to convert target
macros into hooks.
Obviously such moves do require checking the definitions and uses of the
macros in question; you need to make sure you catch all places that use
#ifdef / #if defined etc. on the macro (and make sure they have the same
default). And if you're changing the semantics of the macro from defined
/ undefined to true / false, you need to watch out for any existing
definitions with an empty expansion, or an expansion to 0, etc.
--
Joseph S. Myers
joseph@codesourcery.com