[Image-SIG] portability issue in ImConfig.h

Georg Mischler schorsch@schorsch.com
Thu, 17 Aug 2000 15:03:44 -0400 (EDT)


Patrick Perry wrote:

> 
> Hi guys,
> 
> I was browsing through the source of PIL, and was a little confused when I
> came across ImConfig.h (in the libImaging directory).  This file is full
> of lines like:
> 
> #define SIZEOF_CHAR 1
> #define SIZEOF_DOUBLE 8
> #define SIZEOF_FLOAT 4
> 
> Why are these values hard coded instead of using the "sizeof" macro that's
> part of any ANSI C compiler???  The *only* size that's guaranteed is
> char-- the size of float, double, etc. can change from platform to
> platform.  I hope I'm missing something here-- if I am, fill me
> in.  Otherwise, let's change ImConfig.h to be a little more ANSI
> compliant.
 
 
That depends on your definition of "hard coded".
The ImConfig.h file is generated by the configure script,
which probably uses exactly the sizeof operator you're
advocating. The nice thing with doing it this way is that
it's garanteed to be done *before* compile time.  As far
as I know, this is common practise when "size matters".

ANSI defines sizeof to be evaluated at compile time, but
not earlier. After all, it's an operator (not a macro!),
and as such implemented by the compiler. Unfortunately,
we need it's results already in the preprocessing stage,
which leaves the chosen approach as the only truly
portable solution.


Have fun!

-schorsch

-- 
Georg Mischler  --  simulations developer  --  schorsch at schorsch.com
+schorsch.com+  --  lighting design tools  --  http://www.schorsch.com/