? #define SSVAL(buf,pos,val) (*(uint32 *)((char *)(buf) + (pos)))=((uint32)(val))

Hi, I tried to understand this define, but after a few steps I begin to mess it up...
=>#define SSVAL(buf,pos,val) (*(uint32 *)((char *)(buf) + (pos)))=((uint32)(val))
Is there someone who can explain on a stupid-proof manner what this define means?
Thanks in advance.
AzizLightAsked:
Who is Participating?
 
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
In simple terms, the macro does something like

SSVAL(buf,pos,val)    is like do       buf[pos] = val      or      *(buf+pos) = val

All those complicated parenthesis are just casting operations

(char *)(buf)   ensures the 'buf' pointer points to a characters buffer or converts it.
(pos)              represents the numbers to BYTES to advance pointer
(uint32 *)       converts again the pointer to a pointer to a 32bit value (**after** advancing pointer by 'pos')

finally, contents of pointed data is replaced with a 32bit value: ((uint32)(val))
(uint32)         ensures data to replaces is 32bit


0
 
AxterConnect With a Mentor Commented:
It's setting a buffer at position number (pos) to a value of a 32bit unsigned integer who value is (val)
0
 
AzizLightAuthor Commented:
Thanks a lot.
It wasn't essential to know, but I like to understand what I'm doing....
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.