how to set pointer to a memory to NULL using memset?

后端 未结 9 876
执笔经年
执笔经年 2020-12-11 08:35

I have a structure

typedef struct my_s {

   int x;
   ...
} my_T;

my_t * p_my_t;

I want to set the address of p_my_t to

9条回答
  •  一个人的身影
    2020-12-11 09:32

    The recommended code for setting a pointer to null is assigning 0 (zero). Bjarne Stroustrup does it :) Anyway it is just as expressive as NULL and does not depend on a macro definition.

    Note that NULL is not a keyword, it is not reserved and while it would be confusing to redefine, nothing says that you should not (more than style). A coworker often jokes about defining NULL to something different than 0 in some header just to see how other people's code behave.

    In the upcoming standard there will be a more expressive nullptr keyword to identify a null pointer.

提交回复
热议问题