r/programming • • Jul 23 '08

Ask Programming: What language did you first start, and how old were you?

12 Upvotes

188 comments sorted by

View all comments

Show parent comment

7

u/twanvl Jul 23 '08

First of all, you have the typedefs the wrong way around. The old type comes first,

typedef foo int;
typedef bar int;

Secondly, in C(++) typedef creates an alias, not a new type. So both foo and bar would be ''exactly the same'' as integers, and the compiler will not report an error.

-4

u/munificent Jul 23 '08

First of all, you have the typedefs the wrong way around.

No, I think I got that part right. The alias name comes first, the type it's aliased to afterwards.

So both foo and bar would be ''exactly the same'' as integers, and the compiler will not report an error.

I just tested it, and you're right. Thanks! All this type I thought typedefs were for more than just programmer convenience. Huh.

3

u/[deleted] Jul 23 '08

1

u/munificent Jul 23 '08

Oh, snap. You're right. I rarely use typedefs since I moved to C++.

2

u/[deleted] Jul 27 '08

here is my personal favorite typedef, which I believe are essential in C++.

typedef Brain<Coffee> NewBrain;