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

前端 未结 8 1804
野性不改
野性不改 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:25

    If the pointer is never meant to be dereferenced or otherwise manipulated directly -- IOW, you only pass it as an argument to an API -- then it's okay to hide the pointer behind a typedef.

    Otherwise, it's better to make the "pointerness" of the type explicit.

提交回复
热议问题