473,396 Members | 1,871 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,396 software developers and data experts.

Typedef and Structs

Hello everyone,

I have a question about using typedef with structure definitions. Here
is the example;

typedef struct MyStruct {
...
..
..
} MyStruct_t;

What is the effect of using typedef in this example? What is the
difference of it between the example below

struct MyStruct_t {
...
..
..
};

Thanks for your answers...

Sep 1 '06 #1
2 1684
kasiyil wrote:
I have a question about using typedef with structure definitions.
Here is the example;

typedef struct MyStruct {
...
..
..
} MyStruct_t;

What is the effect of using typedef in this example? What is the
difference of it between the example below

struct MyStruct_t {
...
..
..
};
The effect is that in the former case you have two names, 'MyStruct',
a type-id, and 'MyStruct_t', a typedef-id, which is a synonym for it;
and in the latter case you have only one name, 'MyStruct_t' which is
a type-id. The difference is minimal, as you can see.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 1 '06 #2
kasiyil wrote:
<snip>
typedef struct MyStruct {
...
..
..
} MyStruct_t;

What is the effect of using typedef in this example? What is the
difference of it between the example below

struct MyStruct_t {
...
..
..
};
In C it is necessary to use a typedef if you want to refer to a struct
type without using the keyword struct. In C++ this is no longer
necessary, but there is lots of legacy code that still does this.

Regards,
Bart.

Sep 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: dreamcatcher | last post by:
I always have this idea that typedef a data type especially a structure is very convenient in coding, but my teacher insisted that I should use the full struct declaration and no further...
30
by: stephen henry | last post by:
Hi all, I have a question that I'm having difficulty answering. If I have a struct: typedef struct my_struct_tag{ struct my_other_struct *other; } my_struct_tag
8
by: J Krugman | last post by:
My compiler complains if I do something like this typedef struct { node *next; } node; but it's OK with typedef struct superfluous_identifier { superfluous_identifier *next;
6
by: marabo82 | last post by:
Hi, i know that typedef structs creates an aliases for a particular struct in C++. i m trying to convert .h c++ files to a namespace in C#.net so that i use C++ DLL in my C# application. one of...
17
by: Steve Carter | last post by:
Can someone please explain why the following is not possible? typedef foobar { int x; foobar *next; /* why can't we do this? */ }; Thanks
7
by: Francois Grieu | last post by:
Hello, is the size of a type, defined using typedef as a collection of arrays of unsigned char, the sum of the size of the arrays ? After simplifying my question, it probably is equivalent to:...
8
by: Guillaume Dargaud | last post by:
I just saw the following two lines in /usr/include/usb.h and my head is spinning: struct usb_dev_handle; typedef struct usb_dev_handle usb_dev_handle; What is that supposed to mean ? I...
16
by: mdh | last post by:
A quick ? :-) question about Typedefs. There is a very brief discussion about this in K&R ( p146). Googling this group, there is a surprising dearth of questions about these. From one of the...
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: 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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.