473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Members of a typedef struct

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
3 1572
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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: jimjim | last post by:
Hello, Any help will be much appreciatted. My problem is as follows: I declare as global variables: typedef struct _Node{ ..; ..;}Node; Node *Graph; in a function called initiallise(), I...
2
by: Madhav | last post by:
Hi all, I was going through a piece of code which had a very interesting format. There were two files: one was a .h file, and the other was a .c file. The .c file had a structure defined in it...
2
by: Vincent RICHOMME | last post by:
Hi, I still have problems with some class and their members. I have two classes declared as : typedef struct tagStructB { int iSizeB; char* szTextB;
9
by: Tom Plunket | last post by:
The project I'm currently on makes heavy use of unnamed structures to represent an "object hierarchy" of a sort. E.g. struct BaseObject { int aMember; int anotherMember; // etc.
15
by: Ian Bush | last post by:
Hi All, I'm a bit confused by the following which is causing one of our user's codes fail in compilation: typedef struct SctpDest_S; 1) Is this standard ? 2) If so ( or even if not so ! )...
26
by: Adam Warner | last post by:
Hi all, One cannot return a pointer to an array type in C because C has no first class array types. But one can return a pointer to a struct containing an incomplete array via the illegal but...
14
by: Glen Dayton | last post by:
While looking at some old code I ran across a snippet that increments a pointer to access different members of a structure: .... struct Badness { std::string m_begin; std::string m_param1;...
9
by: nolonger | last post by:
Sample code:- typedef struct __Y { int a; char b; } Y; Y my_struct; Y *my_ptr_struct;
85
by: pereges | last post by:
#include <stdio.h> typedef struct { double x, y, z; }vector; int main(void) { int i;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.