By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,385 Members | 1,737 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,385 IT Pros & Developers. It's quick & easy.

Members of a typedef struct

P: n/a
How do I assess members of a typedef struct?
Example:

typedef struct {
Int16 data1;
Int32 data2;
Char stringData[20];
} MyRecordType;

How would I assess the stringData member?

Thanks,

Diego Acevedo
Dec 28 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Diego Acevedo wrote:
How do I assess members of a typedef struct?
Example:

typedef struct {
Int16 data1;
Int32 data2;
Char stringData[20];
} MyRecordType;

How would I assess the stringData member?

Thanks,

Diego Acevedo


There is no such thing as a `typedef struct'. What you have done above
is create a synonym for the anonymous struct you've defined.

Of course, as there are no such types as `Int16', `Int32' and `Char' in
standard C, I would "assess" the `stringData' member as meaningless.

If you want to *access* a member, it's simple. If you have an instance
of the struct, you use the `.' operator, if you have a pointer to an
instance you use the `->' operator.

But first, you read the FAQ and get a *good* book to use as a reference
(see http://www.accu.org for suggestions).

HTH,
--ag
--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com
http://www.cafepress.com/goldsays
"If you have nothing to hide, you're not trying!"
Dec 28 '05 #2

P: n/a
There is no 'typedef struct', it is just an alias

if you declare an Structure
eg:
structure a
{
short int data1;
int data2;
};

to create an variable of 'structure a'

the syntax would be
struct a <userdefined variable name>

insted if you use

typedef structure a
{
short int data1;
int data2;
} A;

to create an variable of 'structure a'

the syntax would be
A <userdefined variable name>

and there is no Int16 and Int32;

I believe these should be typedefed some where else as

typedef Int16 short int
typedef Int32 int
typedef Char char

there is no difference in accessing them

For accessing

Declare an variable

MyRecordType myRec;

Accessing data1 and data2

myRec.data1 = 20;
myRec.data2 = 40;

Accessing stringData

strcpy (myRec.stringData, "Text max 20 chars");

Best Regards,
Abdur

Dec 29 '05 #3

P: n/a

Diego Acevedo wrote:
How do I assess members of a typedef struct? [...]
typedef struct {
Int16 data1;
Int32 data2;
Char stringData[20];
} MyRecordType;

How would I assess the stringData member?


assuming you have Int16... etc. typedef'ed, you can do it like this:
/***/
MyRecordType mrt, *pMrt;
mrt.stringData;
pMrt->stringData;
/***/

Dec 29 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.