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

前端 未结 8 1672
野性不改
野性不改 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条回答
  • 2021-01-06 11:26

    I prefer leaving the *, it shows there's a pointer. And your second example should be shortened as char* x;, it makes no sense.

    0 讨论(0)
  • 2021-01-06 11:26

    If you look at several existing APIs, it looks as if not putting the pointerness into the type seems better style:

    • the already mentionned FILE *
    • the MYSQL * returned by MySQL's mysql_real_connect()
    • the MYSQL * returned by MySQL's mysql_store_result() and mysql_use_result()

    and probably many others.

    0 讨论(0)
提交回复
热议问题