Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

structure interpret

Posted on 2013-06-28
4
Medium Priority
?
216 Views
Last Modified: 2013-06-28
typedef struct {
	u_int len;
	uint32_t *val;
} bits;

bits b*_obj;
b_obj->val[0];
b_obj->val[1];

Open in new window


Can someone please give me an example with some values. I am confused why it is using [] operator on pointer to uint32_t
0
Comment
Question by:perlperl
[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
  • 2
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 39285590
>> I am confused why it is using [] operator on pointer to uint32_t

That's because

b_obj->val[1];

Open in new window


and

b_obj->val + 1;

Open in new window


are exactly the same. However, the above expressions are meaningless because

a) 'b_obj' (a pointer to 'bits') is never assigned a value
b) 'b_obj->val[1];' is a NUP expression since neither a value is read nor set.

That would make more sense if that was like

typedef struct {
	u_int len;
	uint32_t *val;
} bits;

bits b*_obj = some_memory_area; // or '= &some_variable;'
b_obj->val[0] = 0xff;
b_obj->val[1] = 0xff;
b_obj->len = 2;                         

Open in new window


or

typedef struct {
	u_int len;
	uint32_t *val;
} bits;

bits b*_obj = some_memory_area; // or '= &some_variable;'
unit32_t v1 = b_obj->val[0];
uint32_t v2 = b_obj->val[1];
                                  

Open in new window

0
 

Author Comment

by:perlperl
ID: 39285619
hmmm. so if the len = 3, I can also access b_obj->val[2]  Correct?
0
 
LVL 86

Expert Comment

by:jkr
ID: 39285630
Yes, absolutely.
0
 

Author Closing Comment

by:perlperl
ID: 39285646
Thanks!
0

Featured Post

Independent Software Vendors: 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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

618 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