Solved

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

Posted on 2004-09-25
3
382 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
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

856 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