Solved

structure interpret

Posted on 2013-06-28
4
198 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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…
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 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.

760 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

18 Experts available now in Live!

Get 1:1 Help Now