RE: union to get parts of integer

"Reza Hoorfar" <[email protected]>
Newsgroups gmane.linux.c-programming
Message-ID <[email protected]>
union MyUnion{
	int myInt;
	char myChar[sizeof(int)];
};

void main()
{
	MyUnion m;
	m.myInt = 0x01020304;
	printf("value :%d\n",m.myChar[0]); // -> value : 4
	printf("value :%d\n",m.myChar[1]); // -> value : 3
	printf("value :%d\n",m.myChar[2]); // -> value : 2
	printf("value :%d\n",m.myChar[3]); // -> value : 1
}

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of ratheesh k
Sent: Monday, December 20, 2010 2:10 PM
To: [email protected]
Subject: union to get parts of integer

typedef struct {
char parts[4];
} node ;

int i=0x12345678

((node *)&i)->parts[0];
((node *)&i)->parts[1];
((node *)&i)->parts[2];
((node *)&i)->parts[3];

Is there any mechanism to split into bytes using the power of union ?

-Ratheesh
--
To unsubscribe from this list: send the line "unsubscribe
linux-c-programming" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.