This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: specs: *predefine oddity

On Tue, Nov 02, 1999 at 06:45:57PM +0100, Ralf Corsepius wrote:
> Hi,
> When adding a define (-D...) to *predefines: in gcc's specs, gcc
> apparently implicitly expands these defines into other defines. I am not
> sure if the present behaviour is correct (i.e. "a feature") or if there
> might be something broken (i.e. "a buggy").
> E.g. having this in specs:
> 1)
> *predefines:
> -Dfoo
> gcc -v reports, this to be expanded into
> -Dfoo -D__foo__ -D__foo
> 2)
> *predefines:
> -Dfoo -D__bar__
> Expands to:
> -Dfoo -D__bar__ -D__foo__ -D__bar__ -D__foo
> 3)
> *predefines:
> -Dfoo -D__foo__
> Expands to this weird and unnecessarily lengthy line:
> -Dfoo -D__foo__ -D__foo__ -D__foo__ -D__foo
> Is this really the desired behaviour ? Is it documented somewhere and
> can we rely on this behaviour to be kept in future gcc-versions?

Yes, it is desired beahvior.  It's been that way for the 11+ years I've been
working on GCC.  Yes, it is documented (look for the documentation for
CPP_PREDEFINES in the tm.texi part of the manual).  Yes you should be able to
rely on it it in the future.

> If the answer to all these questions is yes, then probably several
> gcc/config/*.h files which apply CPP_PREDEFINES could be simplified,
> because they explicitly define one or more permutation of
> -Dfoo, -D__foo and -D__foo__.

One key point that you are missing is that CPP_PREDEFINES which is used to
initialize the *predefines spec is handled differently from other specs.
Because of the parsing to add the __'s, it doesn't handle conditionals or used
defined subspecs.  If you need macros expanded conditionally, you have to use
CPP_SPECS (*cpp), and handle the __ expansion yourself.  For example, the
config/a29k/unix.h file defines:

#define CPP_PREDEFINES "-Dam29k -Da29k -Dam29000 -Asystem(unix) -Acpu(a29k) -Amachine(a29k)"

#undef CPP_SPEC
#define CPP_SPEC "%{!m29000:-Dam29050 -D__am29050__}"

Since am29050/__am29050__ is not to be defined if the -m29000 switch is used,
its processing needs to go in CPP_SPEC.

Michael Meissner, Cygnus Solutions
PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886
email:	phone: 978-486-9304	fax: 978-692-4482

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]