Solved

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

Posted on 2004-09-25
3
385 Views
Last Modified: 2012-06-27
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
Comment
Question by:AzizLight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 30

Assisted Solution

by:Axter
Axter earned 35 total points
ID: 12149854
It's setting a buffer at position number (pos) to a value of a 32bit unsigned integer who value is (val)
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 90 total points
ID: 12150470
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
 

Author Comment

by:AzizLight
ID: 12151328
Thanks a lot.
It wasn't essential to know, but I like to understand what I'm doing....
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question