[FIX] via source forge updates

Richard A. O'Keefe ok at atlas.otago.ac.nz
Mon Feb 4 00:51:05 UTC 2002


Tim Rowledge <tim at sumeru.stanford.edu> wrote:
	Meta programming of the C
	compiler would be nice here; can I do anything like
	#if sizeof(sqeakFileOffsetType) == 4
	#define squeakInt64 long long
	#else
	#define squeakInt64 long int
	#endif
	??

No.  Typedefs like squeakFileOffsetType are not defined until after
preprocessing is complete.  You can't even ask for sizeof (int) in
the preprocessor.  Nor can you reliably ask for arithmetic expressions
wider than 32 bits to be evaluated in a C89 preprocessor.

C99 has <inttypes.h> which defines things like int64_t, and some
C89 compilers also have this header.  (In fact all the UNIX C compilers
I use do, as does Code Warrior 5 on the Mac.)

Another approach is to use a "probe program".

    #include <stdio.h>
    #include "squeak-base.h"
    int main(void) {
	printf("#define squeakInt64 %s\n",
	       sizeof (squeakFileOffsetType) == 4 ? "long long" : "long int");
	return 0;
    }

Such a program might generate any number of typedefs & macros based on
things fixed in an earlier phase.

	I actually tried that with no success :-( but there really must be some
	way to do it. A crucial point is that it must be ansi spec, not ISO or
	'it works ok in gcc'. Why is ansi important? Ask me once you've tried
	doing ports to minimal systems with just an ansilibrary and monitor.
	
ANSI C and ISO C are identical, except for badge engineering.
(I guess you mean not relying on anything in the Technical Corrigenda to
the ISO standard.  The base document is the ANSI one renumbered and minus
the rationale.)



More information about the Squeak-dev mailing list