Members of a typedef struct

D

Diego Acevedo

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
 
A

Artie Gold

Diego said:
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
 
A

abdur_rab7

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
 
H

haroon

Diego said:
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;
/***/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,229
Latest member
GloryAngul

Latest Threads

Top