public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Use command line defines vs defining in header files.
@ 2000-08-28 15:04 rlau
  0 siblings, 0 replies; 6+ messages in thread
From: rlau @ 2000-08-28 15:04 UTC (permalink / raw)
  To: gcc

Now, let get back to the my question.
Anyone please.

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Can anyone give me a strong argument as whether defining constants for
conditional compiling as compiler argument vs.
   defining thems in header files?

for examples:



test.h
#ifdef COMPILER_OPT1
:
#else
:
#endif

#ifdef COMPILER_OPT2
:
#else
:
#endif
-------------------------------------------

So, if I would be defining COMPILER_OPT1 as compiler argument, I would do
something like gcc -d COMPILER_OPT1 test.cpp.

If I would defining COMPILER_OPT1 in header files, I would define it in
test.h before #ifdef COMPILER_OPT1.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Use command line defines vs defining in header files.
  2000-08-28 14:34   ` Matt Minnis
  2000-08-28 14:49     ` Michael Meissner
@ 2000-08-28 14:50     ` Gerald Pfeifer
  1 sibling, 0 replies; 6+ messages in thread
From: Gerald Pfeifer @ 2000-08-28 14:50 UTC (permalink / raw)
  To: Matt Minnis; +Cc: gcc

On Mon, 28 Aug 2000, Matt Minnis wrote:
> On a similar note, why is #ifdef XXX used more than #if XXX?

If you #define SOMETHING, #ifdef SOMETHING evaluates to true, but
#if SOMETHING causes an error.

Gerald
-- 
Gerald "Jerry" pfeifer@dbai.tuwien.ac.at http://www.dbai.tuwien.ac.at/~pfeifer/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Use command line defines vs defining in header files.
  2000-08-28 14:34   ` Matt Minnis
@ 2000-08-28 14:49     ` Michael Meissner
  2000-08-28 14:50     ` Gerald Pfeifer
  1 sibling, 0 replies; 6+ messages in thread
From: Michael Meissner @ 2000-08-28 14:49 UTC (permalink / raw)
  To: Matt Minnis; +Cc: gcc

On Mon, Aug 28, 2000 at 03:31:46PM -0500, Matt Minnis wrote:
> On a similar note, why is #ifdef XXX used more than #if XXX?
> 
> Is there a technical reason or just that's the way it has been done?

The two are not the same thing.

	#if name

tests if name != 0 (with undefined names being 0, though I believe some pre-ISO
C compilers would give an error or a warning if name was not defined), while

	#ifdef name

would be positive even if name was defined as either the empty string, or 0.
In addition, if name is not defined as an integer constant expression (for
example, it contains a call or a structure member reference), the plain #if
would barf on it.

	#if defined(name)

is indeed equivalent to #ifdef name, but it is clunkier.

-- 
Michael Meissner, Red Hat, Inc.
PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886, USA
Work:	  meissner@redhat.com		phone: +1 978-486-9304
Non-work: meissner@spectacle-pond.org	fax:   +1 978-692-4482

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Use command line defines vs defining in header files.
  2000-08-28 13:23 ` Jan Dvorak
@ 2000-08-28 14:34   ` Matt Minnis
  2000-08-28 14:49     ` Michael Meissner
  2000-08-28 14:50     ` Gerald Pfeifer
  0 siblings, 2 replies; 6+ messages in thread
From: Matt Minnis @ 2000-08-28 14:34 UTC (permalink / raw)
  To: gcc

On a similar note, why is #ifdef XXX used more than #if XXX?

Is there a technical reason or just that's the way it has been done?

Thanks,

Matt Minnis

At 03:23 PM 8/28/2000, Jan Dvorak wrote:
>On Mon, Aug 28, 2000 at 03:11:32PM -0500, rlau@csc.com wrote:
> >
> > Can anyone give me a strong argument as whether defining constants for
> > conditional compiling as compiler argument vs.
> >    defining thems in header files?
> >
> > for examples:
> >
>
>Not all compilers supports -D, and you can get to line length limit on 
>some systems (255 on dos ?). -D is useful when you have to specifi one or 
>more really dependent argumenst (such as -DHAVE_CONFIG_H in autoconf does), and
>you get better readibility of code to search for #define than search 
>through all the (generated) Makefile.
>
>Jan Dvorak <johnydog@go.cz>

Cthulhu for President. Why settle for a lesser evil?

=========================================================
Preferred Resources          (314) 567-7600 phone
701 Emerson rd.              (314) 993-6699 fax
Suite 475		       mminnis@prefres.com
St. Louis, MO
63141
=========================================================

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Use command line defines vs defining in header files.
  2000-08-28 13:11 rlau
@ 2000-08-28 13:23 ` Jan Dvorak
  2000-08-28 14:34   ` Matt Minnis
  0 siblings, 1 reply; 6+ messages in thread
From: Jan Dvorak @ 2000-08-28 13:23 UTC (permalink / raw)
  To: rlau; +Cc: gcc

On Mon, Aug 28, 2000 at 03:11:32PM -0500, rlau@csc.com wrote:
> 
> Can anyone give me a strong argument as whether defining constants for
> conditional compiling as compiler argument vs.
>    defining thems in header files?
> 
> for examples:
> 

Not all compilers supports -D, and you can get to line length limit on some systems (255 on dos ?). -D is useful when you have to specifi one or more really dependent argumenst (such as -DHAVE_CONFIG_H in autoconf does), and
you get better readibility of code to search for #define than search through all the (generated) Makefile.

Jan Dvorak <johnydog@go.cz>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Use command line defines vs defining in header files.
@ 2000-08-28 13:11 rlau
  2000-08-28 13:23 ` Jan Dvorak
  0 siblings, 1 reply; 6+ messages in thread
From: rlau @ 2000-08-28 13:11 UTC (permalink / raw)
  To: gcc

Can anyone give me a strong argument as whether defining constants for
conditional compiling as compiler argument vs.
   defining thems in header files?

for examples:



test.h
#ifdef COMPILER_OPT1
:
#else
:
#endif

#ifdef COMPILER_OPT2
:
#else
:
#endif
-------------------------------------------

So, if I would be defining COMPILER_OPT1 as compiler argument, I would do
something like gcc -d COMPILER_OPT1 test.cpp.

If I would defining COMPILER_OPT1 in header files, I would define it in
test.h before #ifdef COMPILER_OPT1.



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2000-08-28 15:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-08-28 15:04 Use command line defines vs defining in header files rlau
  -- strict thread matches above, loose matches on Subject: below --
2000-08-28 13:11 rlau
2000-08-28 13:23 ` Jan Dvorak
2000-08-28 14:34   ` Matt Minnis
2000-08-28 14:49     ` Michael Meissner
2000-08-28 14:50     ` Gerald Pfeifer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).