Anup Joshi wrote:
> hello Vic thank you for all your responses.
> i was just trying to use union as an alternative to that problem and hence
> following your response i changed the array to contain 2 elements according
> to the 'endian' thing., here is the code :
>
> ==========
> #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));
> }
>
> ==========
>
> the only changed thing is uchar y[1]; is replaced by uchar y[2];
>
> i compiled and executed the program using turbo c++ 3
get rid of it, it's a very old compiler and doesn't handle standard C++
> and it gave the same output as it gave previously even sizeof showed out the
> size of myvals to be 2! i have some queries to you and others in this group
> please clarify them:
> 1. the code is successfully executing and giving satisfactory output, but is
> that output compiler dependant though it was using a feature of C?
you STILL haven't handled the "endian" problem
> if so then why is it, i mean what is the difference?
> 2. can i in any case use unions safely for brians problem?
>
NO
> 3. why does sizeof showed the size of myvals to be 2 bytes?
>
how big do you expect it to be?
> again thanks for your comments and am waiting for your reply.
>
> With Regards
>
> Anup Joshi
>
>
> ---------------------------------
> Need a vacation? Get great deals to amazing places on Yahoo! Travel.
>
> [Non-text portions of this message have been removed]
>
>
>
> To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>.
> Yahoo! Groups Links
>
>
>
>
>