Re: [GD-General] meaning of sizeof(int) on all plateform
Brought to you by:
vexxed72
From: J C L. <cl...@ka...> - 2003-06-30 01:58:52
|
On Fri, 27 Jun 2003 16:52:01 -0700 Jay Woodward <woo...@Ro...> wrote: > Hold on -- it seems to me that the existence of forward declaration > necessitates that all pointers be the same size. Nope. ANSI doesn't require it. It merely requires that a void* be able to store a pointer of any other type, and that a void* can be converted to a pointer of any other type without loss (and get the proper address). Now as to how the compiler accomplishes this is of course part of that undefined black magic which is left up to compiler authors. ObNote: I've worked on platforms where different pointer types had different sizes and the compilers handled it just fine. > I suppose you wouldn't lose information when casting, as long as it's > guaranteed that sizeof(void*) >= sizeof(any other pointer). Still, my > understanding has always been that all pointers are the same size. Even that's not required. You're assuming a flat memory model and that pointers are basically integral types. This is not required and is in fact not true on several platforms where pointers are variously complex structures. The real kickers are those systems where: type_foo *ptr1, *ptr2; ...code that messes with ptr1 and ptr2... if (memcmp (ptr1, ptr2, sizeof (ptr1))) { printf ("memcmp comparison failed!\n"); } if (ptr1 == tr2) { printf ("pointer comparison succeeded!\n"); } On some hosts you can get cases where both printf() calls will be executed. -- J C Lawrence ---------(*) Satan, oscillate my metallic sonatas. cl...@ka... He lived as a devil, eh? http://www.kanga.nu/~claw/ Evil is a name of a foeman, as I live. |