# Thread: Can someone explain the following macro in detail?

1. ## Can someone explain the following macro in detail?

#define yahoo_put32(buf, data) ( \
(*((buf)) = (unsigned char)((data)>>24)&0xff), \
(*((buf)+1) = (unsigned char)((data)>>16)&0xff), \
(*((buf)+2) = (unsigned char)((data)>>8)&0xff), \
(*((buf)+3) = (unsigned char)(data)&0xff), \
4)

#define yahoo_get32(buf) ((((*(buf) )&0xff)<<24) + \
(((*((buf)+1))&0xff)<<16) + \
(((*((buf)+2))&0xff)<< 8) + \
(((*((buf)+3))&0xff)))

why is there a 4 at last on the yahoo_put32?

2. << !! Posting Code? Read this First !! >>

3. The first macro unpacks 4 bytes stored in 'data' to 'buf'
The second one packs those 4 bytes to make the original data

4. Originally Posted by Sipher
The first macro unpacks 4 bytes stored in 'data' to 'buf'
The second one packs those 4 bytes to make the original data
on the first one, the unpacking, is the data's most significant 8 bits putting into the buf?

I thought the most significant 8 bits should be putting into buf+3?

and why is there's a 4 at the end?

5. Sorry, my bad. See below.

6. Originally Posted by lilzz
I thought the most significant 8 bits should be putting into buf+3?
Data are stored in Big Endian. It's a convertion of the web.

Originally Posted by lilzz
and why is there's a 4 at the end?
It's a comma trick. As you see, all four previous statements have a comma at the end instead of a semicolon. This essentially means the the first macro returns 4 when "executed".