64,282
社区成员
发帖
与我相关
我的任务
分享
char *pChar =NULL;
pChar= (char*)malloc(0);
if (pChar != NULL )
cout<<"pChar != NULL\n" ;
来自C99的最权威的解释:
If the size of the space requested is zero, the behavior is implementationdefined:
either a null pointer is returned, or the behavior is as if the size were some
nonzero value, except that the returned pointer shall not be used to access an object.
所以最后答案是:
implementationdefined
//...
int iSize = 0 ;
//...
char *pChar =NULL;
pChar= (char*)malloc(iSize );
if (pChar != NULL )
cout<<"pChar != NULL\n" ;
memset(pchar , 0 , iSize ) ;
char *pPos = strstr(pchar , "size:") ;