compiling on solaris 9

skaller skaller at
Sat Sep 15 13:17:47 EDT 2007

On Sat, 2007-09-15 at 15:42 +0200, Sven Panne wrote:
> On Saturday 15 September 2007 13:58, skaller wrote:
> > [...]
> > 1. Measure the size (and alignment, while at it) of all the
> > integer types. (trial execute and run).
> > [...]
> > 4. For the ones provided, AND size_t, ptrdiff_t, check
> > their size (and signedness). (trial execution)
> Small additional note: One can determine the size and alignment *without* 
> always resorting to trial execution. Autoconf does this by an 
> ingenious "evaluation by compilation" technique in case of cross-compilation, 
> see the implementation of AC_CHECK_SIZEOF and AC_CHECK_ALIGNOF.

Hmm .. I guess that's possible with some kind of type checking
hack? .. (I don't use autoconf but thanks for that info .. I will
have a look, it would be cool to get better cross-compilation

> > [...]
> > 6. Test what the typedefs found are actually aliased to
> > using C++ (there is no other portable way to do this).
> > (Trial execution)
> To be honest, I don't understand that point...

The point is that on most systems knowing the size of
say 'intptr_t' does NOT tell you which integer type it
is aliased to if there are two of them, eg:

	// gcc, amd64, Linux:
	sizeof(intptr_t) == 8
	sizeof(long) == 8
	sizeof(long long)== 8

so intptr_t is aliased to long or long long .. which one?
Short of examining the header file source code, the only
way to find out is in C++ with overloading:

	void me(long){ printf("long"); }
	void me(long long) { printf("long long"); }
	me( (intptr_t)0 );

Unfortunately EVERY system I know of has at least one more integer 
type available than actual integer sizes: on Win64 int and long have
the same size, and of course long long must be used for the 
"integer the size of a pointer".

This is what bit the Ocaml library.. if you need such an animal
it MUST be called 'my_intptr_t', since no other name is standard
than one you define yourself.

Yeah, this is a REAL pain .. but look at any 'professional' 
C library (OpenGL, GMP, etc etc) and they all do it.

BTW: in C, it usually doesn't matter which of two integers types
of the same size you use .. but in C++ it does, precisely because
it affects overloading. But note C99 has 'overloading' of a kind,
and consider using "C++ safe" C when possible, I think it is worth
ensuring 'my_intptr_t' aliases the same type as 'intptr_t' if the
latter is defined.

John Skaller <skaller at users dot sf dot net>
Felix, successor to C++:

More information about the Glasgow-haskell-users mailing list