Re: [algogeeks] Re: Endian-ness check

2010-06-16 Thread Sundeep Singh
@Lego: I am sorry I missed the address of operator... I wanted to type: printf(%d, *(char *) (0x0002)) But even the above is incorrect since it is not possible to take address of a literal in C/C++. The best way is: const int i=0x0002; printf(%d, *(char *) (i)); If this print 2, then its

Re: [algogeeks] Re: Endian-ness check

2010-06-15 Thread Sundeep Singh
@saurav: your code will always print 2 irrespective of the system's endianness! correct thing to do is: printf(%d, *(char *) (0x0002)) --Sundeep. On Mon, Jun 14, 2010 at 3:02 AM, Minotauraus anike...@gmail.com wrote: How about a pointer? :D On Jun 13, 5:56 am, debajyotisarma

Re: [algogeeks] Re: Endian-ness check

2010-06-15 Thread Debajyoti Sarma
@ souravsain Don't understand your solution. if u type convert to char how u can say that msb is in higher memory address? i think (char) will alway give the value of the lsb. How u r checking endian ness? normal endian ness check program main() { int i=1; char *p=(char*)i; if(*p==1) printf(Small

Re: [algogeeks] Re: Endian-ness check

2010-06-15 Thread Lego Haryanto
On Mon, Jun 14, 2010 at 5:13 AM, Sundeep Singh singh.sund...@gmail.comwrote: @saurav: your code will always print 2 irrespective of the system's endianness! correct thing to do is: printf(%d, *(char *) (0x0002)) --Sundeep. ... dereferencing a very low address pointer, are you sure?

Re: [algogeeks] Re: Endian-ness check

2010-06-15 Thread Piyush Verma
printf(%d,12424); will give the efficient solution if it print 1 then little indian otherwise big endian. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this

[algogeeks] Re: Endian-ness check

2010-06-13 Thread souravsain
Printf(%d,(char)2); If this print 2 then lsb is 2, else if 0 then msb is 2 On Jun 13, 5:56 pm, debajyotisarma sarma.debajy...@gmail.com wrote: Is it possible to check endianness of a system in C without creating variable?  i.e. Program should not contain any variable. -- You received this