delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/03/25/10:45:49

Date: Thu, 25 Mar 1999 10:45:45 -0500
Message-Id: <199903251545.KAA23500@envy.delorie.com>
From: DJ Delorie <dj AT delorie DOT com>
To: djgpp AT delorie DOT com
In-reply-to: <Pine.GSO.3.96.990325095712.28097B-100000@delta.ds2.pg.gda.pl>
(message from Wojciech Piechowski on Thu, 25 Mar 1999 10:02:05 +0100
(MET))
Subject: Re: Preprocessor hates sizeof
References: <Pine DOT GSO DOT 3 DOT 96 DOT 990325095712 DOT 28097B-100000 AT delta DOT ds2 DOT pg DOT gda DOT pl>
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> #if (sizeof(Box) > BOXGRAIN)

The problem is that the #if lines are handled by the preprocessor, but
the sizeof() functions are handled by the compiler.  The preprocessor
doesn't have enough information to figure out what sizeof() is.  So,
the only option (and the most portable one) is to do these checks
while the program is running, like this:

main()
{
  assert(sizeof(Box) <= BOXGRAIN);

Then, you can turn on/off the assertion checks via -DNDEBUG (defining
it disables all assertions for speed).

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019