thank you all of you for your responses but i still cant get one thing, i was 
successfully able to compile my recent code on gcc v3.42 also, here is the code 
again:

=====
#include <stdio.h>

union vals {
    unsigned short x;
    unsigned char y[2];
} myvals;

int main() {
    myvals.y[0] = 1;  //lsb
    myvals.y[1] = 21; //msb

    printf("%d", myvals.x);
    printf("\n %d", sizeof(myvals));
}

compiled using command: gcc union.c -o myunion.exe
====
and output again is 
5377 
 2
=====
so according to Vic i havent solved the endian problem but i cant understand 
where the problem actually is in this code ???

second thing is the sizeof union shows up to be 2 but i was expecting it to be 
3 (i thought the array is of 3 bytes though it may contain only two elements) 
because i changed the array from uchar y[1](sizeof gave 2)  to uchar y[2](size 
2 again)!!!! why does this happen???

and now if union is the feature of c itself why cant i use it to solve brians 
problem???

my questions might be silly becoz im a newbie hence i have turned up to you 
gurus for clarifying my doubts. thanks for patiently responding me 

with regards

anup

       
---------------------------------
Boardwalk for $500? In 2007? Ha! 
Play Monopoly Here and Now (it's updated for today's economy) at Yahoo! Games.

[Non-text portions of this message have been removed]

Reply via email to