Solved

structure interpret

Posted on 2013-06-28
4
206 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
  • 2
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

828 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