[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] Clean code to be 64bit clean

From: Branko Čibej <brane_at_xbc.nu>
Date: 2003-12-01 00:04:03 CET

Jay 'Whip' Grizzard wrote:

>>>Moreover, in general long is only
>>>type that is supposed (in practice) to hold void *, but this is not
>>>required by standard, so you should not count on it everywhere.
>>It's a bit off-topic, but the ISO C 99 stdint.h header optionally
>>provides intptr_t and uintptr_t. When these types are provided it is
>>guaranteed that a void* can be cast to a [u]intptr_t and then cast
>>back to the original void* value.
>I'm not familiar with the C99 spec (someone feel free to buy me a copy! ;),
>but from the names of the types, intptr_t (etc) seem to be integer pointers.
Well, I'm impressed. First you admit you don't know what you're talking
about, then you proceed at great length. :-)

intptr_t is an integer type that is wide enough to store a void* without
loss of precision, and a cast from void* to intptr_t and back is
guaranteed to preserve the pointer value.

>The subversion code being talked about doesn't convert int pointers back
>and forth from (void *) -- it converts (int) back and forth from (void *).
>This is not, has not been, and never will be either legal,
There is no legal code. There is only valid code (or better yet,
standard-conforming code).

And besides, C99 does specify the semantics of pointer-to-int
conversions, paragraphs 5 and 6.

>or a good thing to do.
Depends on what you're doing, right?

> There only requirement with (void *) is that any type of
>pointer can be cast to (void *) and then back to its original type.
Nope. That guarantee only holds for object pointer types, not for
function pointers.

>There's no guarantee that any other type can be cast to/from (void *)
>without damage --
Nope again, casts to intptr_t are well-defined, see above.

>And, indeed, on some obscure platforms (admittedly, not
>any that subversion supports, I don't think), there actually aren't any
>integer datatypes capable of holding pointer datatypes without damage.
In that case, intptr_t won't be defined on that platform. Although note
that intptr_t doesn't have to be an alias for any other integer type, so
it's quite all right for it to be wider than "long long", for example.

>The right answer to this type of problem is almost always "write the code
>correctly" -- which is to say, don't treat (void *) and ([long] int) as
>interchangeable, because they aren't.
I can agree with that part, anyway. :-)
Although again, in this case, the void* cast to int is never interpreted
as a pointer.

Brane Čibej   <brane_at_xbc.nu>   http://www.xbc.nu/brane/
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Mon Dec 1 00:05:08 2003

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.