Solved

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

Posted on 2004-09-25
3
380 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks a lot.
It wasn't essential to know, but I like to understand what I'm doing....
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now