• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 390
  • Last Modified:

? #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.
0
AzizLight
Asked:
AzizLight
2 Solutions
 
AxterCommented:
It's setting a buffer at position number (pos) to a value of a 32bit unsigned integer who value is (val)
0
 
Jaime OlivaresCommented:
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
 
AzizLightAuthor Commented:
Thanks a lot.
It wasn't essential to know, but I like to understand what I'm doing....
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now