[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: Jani Averbach <jaa_at_jaa.iki.fi>
Date: 2003-11-30 22:16:36 CET

On 2003-11-30 21:58+0100, Tobias Ringstrom wrote:
> Jani Averbach wrote:
> >
> >This message is a little bit bogus, only problem seems to be that
> >there are tree compiler warnings of void * to integer conversion or
> >vice versa (when orginal data has been integer any way from the start).
>
> I'm not sure I understand what the problem is here. Do you really get
> a compiler warning if you cast a void* to an int?

Yep [1], this is a 64bit [2] system. It seems to be that in 32bit gcc
systems sizeof(int) == sizeof(long). 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.

So in theory casting void * -> int is not a safe operation, but when
we are using void * just carrying data, in fact, it is.

BR, Jani

1)
../svn/trunk/subversion/libsvn_client/ssl_server_trust_providers.c:61:
warning: cast from pointer to integer of different size
...

2)
#include <stdio.h>

int
main()
{
    printf("int %d\n", sizeof(int));
    printf("long %d\n", sizeof(long));
    printf("void * %d\n", sizeof(void *));
    return 0;
}

./a.out

int 4
long 8
void * 8

-- 
Jani Averbach
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sun Nov 30 22:17:07 2003

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