M
MisterE
What happens when you type cast like this:
(note this is code i just typed cause I dont have a compiler ATM):
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char*argv[])
{
unsigned char c[] = {0,1,2,3,4,5,6,7,8,9,10};
unsigned int *i1, *i2, *i3;
i1 = &c[0];
i2 = &c[1];
i3 = &c[2];
printf("%x %x %x",*i1,*i2,*i3);
return 0;
}
What output will be printed? I have noticed that some some systems require
integers to be from alligned address etc. others don't. One system has bytes
in i2 and i3 that are not part of c array at all (ie outputting things like
0xFF01 0xFE02 0xFF03)
Is the behavoir defined in anyway at all for anything? Or should the value
of the whole integer be undefined?
The reason I ask this is I have to port some craptastic code that has
pointers of different types randomly pointing to position in an array of
chars... and as you would expect its behaves differently on every compiler.
(note this is code i just typed cause I dont have a compiler ATM):
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char*argv[])
{
unsigned char c[] = {0,1,2,3,4,5,6,7,8,9,10};
unsigned int *i1, *i2, *i3;
i1 = &c[0];
i2 = &c[1];
i3 = &c[2];
printf("%x %x %x",*i1,*i2,*i3);
return 0;
}
What output will be printed? I have noticed that some some systems require
integers to be from alligned address etc. others don't. One system has bytes
in i2 and i3 that are not part of c array at all (ie outputting things like
0xFF01 0xFE02 0xFF03)
Is the behavoir defined in anyway at all for anything? Or should the value
of the whole integer be undefined?
The reason I ask this is I have to port some craptastic code that has
pointers of different types randomly pointing to position in an array of
chars... and as you would expect its behaves differently on every compiler.