In C, is it good form to use typedef for a pointer?

前端 未结 8 1786
野性不改
野性不改 2021-01-06 10:46

Consider the following C code:

typedef char * MYCHAR;
MYCHAR x;

My understanding is that the result would be that x is a pointer of type \"

8条回答
  •  Happy的楠姐
    2021-01-06 11:03

    I don't particularly like typedef to a pointer, but there is one advantage to it. It removes confusion and common mistakes when you declare more than one pointer variable in a single declaration.

    typedef char *PSTR;
    ...
    PSTR str1, str2, str3;
    

    is arguably clearer than:

    char *str1, str2, str3;  // oops
    

提交回复
热议问题