[PATCH] Fix cast int-to-pointer and pointer-to-int
Paulo César Pereira de Andrade
pcpa at mandriva.com.br
Thu Feb 5 18:50:29 PST 2009
Corbin Simpson wrote:
>>> Forgive my stupidity, but isn't it a C language rule that
>>> sizeof(long) == sizeof(void *) is always true?
>>
>> No. As said earlier in this thread there are IL32P64 systems.
>
>
> C only makes one guarantee regarding sizeof() and primitives, and that
> is that sizeof(char) == 1.
>
> ~ C.
I think I was just remembering some old C book I read. I think
I meant to say sizeof(long) >= sizeof(void*). But probably this
was not a guarantee, just probably what was true at the time the
book was written.
I did not follow much "hardware" programming discussions for
quite some time. Just remembering when I switched my "hobby"
programming from Turbo C in DOS to gcc in FreeBSD 2.0 (4 bytes
ints and easy access to large vectors were awesome :-)
But about type conversions, imo, casts are evil. This may
be required regularly in C++, but one should be able to write
things like:
void a(struct t1 *arg) { b(t1); }
void *b(void *ptr) { struct t1 *local = ptr; ...; return 0; }
But this is a C thing (I have a project of a C like language
that has runtime type/boundaries information to handle those),
as it would make it easy to convert t1 to t2, etc, what could
be a "disaster" in C++.
Since there are already systems where sizeof(long) < sizeof(void*),
then some things can be tricky.
Maybe in less then a decade we will also be using 128 bit
computers, or why not, even more; should be enough at around
"64 bytes" computers, where it should be possible to index every
particle of the universe with a distinct number :-)
Paulo
More information about the xorg
mailing list