Keil Logo Arm Logo

Discussion Forum

accessing array of ptr in the structures

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Details Message
Read-Only
Author
jegu jj
Posted
29-Dec-2011 07:20 GMT
Toolset
None
New! accessing array of ptr in the structures

i've declared a structure as

typedef struct elem
{ int a;
void *b[20];
}e;

how can i access the array of (void) pointer inside a structure???

e.b ???

- is this correct manner of accessing???

Read-Only
Author
Mike Kleshov
Posted
29-Dec-2011 07:55 GMT
Toolset
None
New! RE: accessing array of ptr in the structures

You seem to be confused about very basic things in C programming. Read a book on C. K&R is a good one.

Read-Only
Author
Per Westermark
Posted
29-Dec-2011 13:05 GMT
Toolset
None
New! RE: accessing array of ptr in the structures

The big issue is what you intend to do with your void pointers? Just store generic addresses or abuse them by typecast them to a lot of different types depending on time of day or your mood?

Most probably, you are running headlong into a very bad design.

Read-Only
Author
Dan Henry
Posted
29-Dec-2011 16:31 GMT
Toolset
None
New! RE: accessing array of ptr in the structures

"e.b ???

- is this correct manner of accessing???"

No, 'e' is a type, not an object that can be accessed.

Read-Only
Author
Per Westermark
Posted
29-Dec-2011 21:39 GMT
Toolset
None
New! RE: accessing array of ptr in the structures

"No, 'e' is a type, not an object that can be accessed."

The use of typedef together with structures almost always results in confusion for beginners. How it can be possible to give a name both before and after the struct, and still not end up with a variable of that type.

Read-Only
Author
Dan Henry
Posted
31-Dec-2011 00:01 GMT
Toolset
None
New! RE: accessing array of ptr in the structures

"The use of typedef together with structures almost always results in confusion for beginners."

My observation has been that beginners tend to overuse typedef without questioning the merits of using typedefs versus explicit structs. This is only my opinion; in instances where the user doesn't really care about or access a structure's members (e.g. FILE in stdio.h) typedef'ing a struct has merit, but if a user's code accesses members using "." or "->" operators, I don't see the value in hiding an object's "structness" behind a typedef name. Again, that's just my opinion, but I might remember it also being the opinion of pundits on comp.lang.c.

Read-Only
Author
Hans-Bernhard Broeker
Posted
31-Dec-2011 10:28 GMT
Toolset
None
New! RE: accessing array of ptr in the structures

I believe the reason most people prefer to typedef every struct, union and enum is the same that drives a good part of C's syntax: brevity. People want to be able to just write "foo" instead of "struct foo" every time they use one.

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Keil logo

Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.