Re: 16 bit pointer typecast on 16 bit system
- From: Chris Dollin <chris.dollin@xxxxxx>
- Date: Mon, 03 Jul 2006 12:23:01 +0100
michaelquinlivan@xxxxxxxxx wrote:
yes, you should get 0x102 (if it is Big-endian) or 0x201 (if it is
Little-endian) but definitely not 0x1.
I've confirned this with the following test program in gcc:
#include <stdio.h>
char a[] = {0,1,2,3,4};
short b;
int main()
{
b = *(short *)(a+1);
printf("b = 0x%x\n",b);
return 0;
}
It prints the result "b = 0x201" (on an x86, which is little-endian).
I'd say that your compiler is broken...
I'd say your expectations are broken.
You take a value that isn't and never has been pointer-to-short, forcibly
convert it to pointer-to-short, and dereference it -- that sounds to me
like it would generate undefined behaviour.
--
Chris "seeker" Dollin
"I'm still here and I'm holding the answers" - Karnataka, /Love and Affection/
.
- References:
- 16 bit pointer typecast on 16 bit system
- From: Christian Wittrock
- Re: 16 bit pointer typecast on 16 bit system
- From: michaelquinlivan
- 16 bit pointer typecast on 16 bit system
- Prev by Date: Re: 16 bit pointer typecast on 16 bit system
- Next by Date: Re: how to convert char* to File *
- Previous by thread: Re: 16 bit pointer typecast on 16 bit system
- Next by thread: Re: 16 bit pointer typecast on 16 bit system
- Index(es):
Relevant Pages
|
|