我试图用一个简短的CGI脚本来使用夹板,但是得到这个错误:
Null storage passed as non-null param: mysql_init(NULL)
如果mysql_init是NULL,则定义它返回一个新值,如果不是,则将结果存储在param中。但是,如果我试着
MYSQL* connection;
mysql_init(connection);我会得到:
Variable connection used before definition
如何解决这个问题?当然,一种方法是注释mysql.h,这样夹板就不会抱怨了。是我唯一的解决办法吗?
发布于 2014-08-07 11:00:37
您可以编辑mysql.h以将该参数注释为/*@null@*/,也可以禁用该特定代码行的警告。
/*@-nullpass@*/
connection = mysql_init(NULL);
/*@=nullpass@*/顺便说一下,请注意不要将未初始化的变量传递给函数:
MYSQL* connection; /* this pointer contains garbage at this point */
mysql_init(connection); /* this may get a segmentation fault */相反,您应该这样做:
MYSQL* connection = NULL; /* initialize to NULL */
connection = mysql_init(connection); /* get a hold of the new object created */https://stackoverflow.com/questions/25179289
复制相似问题