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 char ??

+4
source share
3 answers

That's why I always bind *to a name, not a type.

When entering

typedef const char *PSTR;

you must read what *PSTRis it const char, therefore PSTRis the address const char.

So if you type

typedef const char *PSTR,
                   *LPSTR,
                   OTHER;

OTHERand *LPSTRequal const charin the same way *PSTR.

+3
source

typedef is NOT an alias .. so if

typedef const char* PSTR, LPSTR;

PSTR is a pointer, LPSTR is a char

0
source

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

0
source

Source: https://habr.com/ru/post/1664269/


All Articles