S
shaanxxx
I have following programme:
#include<stdio.h>
int main()
{
int i=1;
char *ptr=(char *)&i;
if (*ptr)
{
printf("Little Indian\n");
}
else
{
printf("Big Indian\n");
}
printf("%d %d %d\n",sizeof(void
*),sizeof(sizeof(char)),sizeof(char));
return 0;
}
I used %d to print values returned from sizeof. I am wondering why
this programme gives right result on 64bit machines. Somewhere on this
group , i have seen suggestion that %d should not be used. Thats why i
wanted to test %d with sizeof on big Indian 64bit where it should
fail(as per my understanding, And understanding can go wrong).
any comment on this would be appreciated.
I replaced %d with %c , second printf doesnt print any thing.
$ cc -xarch=v9 print.c -o print
$ ./print
Big Indian
8 8 1
$ uname -a
SunOS sunflare 5.8 Generic_108528-18 sun4u sparc SUNW,Ultra-4
13:02:04-odali@sunflare
redhats$ make print
cc print.c -o print
redhats$ ./print
Little Indian
8 8 1
redhats $ uname -a
Linux redhats.xxx.com 2.6.9-34.ELsmp #1 SMP Fri Feb 24 16:56:28 EST
2006 x86_64 x86_64 x86_64 GNU/Linux
#include<stdio.h>
int main()
{
int i=1;
char *ptr=(char *)&i;
if (*ptr)
{
printf("Little Indian\n");
}
else
{
printf("Big Indian\n");
}
printf("%d %d %d\n",sizeof(void
*),sizeof(sizeof(char)),sizeof(char));
return 0;
}
I used %d to print values returned from sizeof. I am wondering why
this programme gives right result on 64bit machines. Somewhere on this
group , i have seen suggestion that %d should not be used. Thats why i
wanted to test %d with sizeof on big Indian 64bit where it should
fail(as per my understanding, And understanding can go wrong).
any comment on this would be appreciated.
I replaced %d with %c , second printf doesnt print any thing.
$ cc -xarch=v9 print.c -o print
Big Indian
8 8 1
$ uname -a
SunOS sunflare 5.8 Generic_108528-18 sun4u sparc SUNW,Ultra-4
13:02:04-odali@sunflare
redhats$ make print
cc print.c -o print
redhats$ ./print
Little Indian
8 8 1
redhats $ uname -a
Linux redhats.xxx.com 2.6.9-34.ELsmp #1 SMP Fri Feb 24 16:56:28 EST
2006 x86_64 x86_64 x86_64 GNU/Linux