Dean
Dean

Reputation: 6960

Typedef with multiple outputs

I just found out that the following is valid C++

typedef const char* PSTR, *LPSTR;

my question is: are PSTR and LPSTR the same alias?

Why if I change it to

typedef const char* PSTR, LPSTR;

I get that LPSTR is a char??

Upvotes: 4

Views: 108

Answers (3)

Boiethios
Boiethios

Reputation: 42769

That is why I always stick the * to the name and not to the type.

When you type

typedef const char *PSTR;

you must read that *PSTR is a const char, so PSTR is the address of a const char.

So if you type

typedef const char *PSTR,
                   *LPSTR,
                   OTHER;

OTHER and *LPSTR are const chars just as *PSTR.

Upvotes: 3

Yup it's a char. The same rules for deducing the type of a variable in variable definitions apply in a typedef definition.

Upvotes: 0

LeoChu
LeoChu

Reputation: 766

typedef is NOT alias..so if

typedef const char* PSTR, LPSTR;

PSTR is a pointer, LPSTR is a char

Upvotes: 0

Related Questions