阅读背景:

如果C中的结构初始化失败,则返回NULL?

来源:互联网 

I have this C code :

我有这个C代码:

#include<stdio.h>

typedef struct {
    int foo;
} MyStruct;

MyStruct init_mystruct(void);

int main(void) {

    MyStruct mystruct   = init_mystruct();

    if( mystruct == NULL ) {
        /* error handler */
    }

    return(0);
}

MyStruct init_mystruct(void) {

    MyStruct mystruct;
    int is_ok   = 1;

    /*
     * do something ...
     */

    /* everything is OK */
    if( is_ok )
        return mystruct;
    /* something went wrong */
    else
        return NULL;
}
#include<stdi



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: