Typedef - multiple declarations

D

Dave

Hi all,

I was wondering if when I use the typedef command, I can typedef multiple names.

EX)

typedef struct foo {
foo *next;
foo *prev;
int val;
} nameOne, nameTwo;

Can I now use nameOne and nameTwo interchangeably?

Dave
 
B

Ben Pfaff

I was wondering if when I use the typedef command, I can typedef multiple names.

`typedef' is not a command. C does not have commands. `typedef'
is syntactically, but not semantically, a storage class
specifier.

Yes, you can declare multiple typedef names in a single
declaration.
typedef struct foo {
foo *next;
foo *prev;

Unless you already typedef `foo', those two declarations will
need to be written `struct foo *', not `foo *'.
int val;
} nameOne, nameTwo;

Can I now use nameOne and nameTwo interchangeably?

Yes. As C99 6.7.7 says, "A typedef declaration does not
introduce a new type, only a synonym for the type so specified."
 
C

CBFalconer

Dave said:
I was wondering if when I use the typedef command, I can typedef
multiple names. EX)

typedef struct foo {
foo *next;
foo *prev;
int val;
} nameOne, nameTwo;

Can I now use nameOne and nameTwo interchangeably?

Yes, but why would you want to? However it might be useful to
make that:

} nameOne, *nameOnePtr;

and you probably need to replace "foo" by "struct foo" within the
definition, unless foo refers to something else entirely.
 
M

Micah Cowan

Hi all,

I was wondering if when I use the typedef command, I can typedef multiple names.

EX)

typedef struct foo {
foo *next;
foo *prev;
int val;
} nameOne, nameTwo;

Can I now use nameOne and nameTwo interchangeably?

Yup.

-Micah
 

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
474,083
Messages
2,570,591
Members
47,212
Latest member
RobynWiley

Latest Threads

Top