[英]implicit declaration of function C mysql
typedef struct database
{
char *host;
char *user;
char *pass;
char *name;
MYSQL *mysql;
MYSQL_RES *result;
MYSQL_ROW row;
}database_t;
extern database_t db;
........................ ........................
MYSQL* mysql_connection_setup(database_t db)
{
//MYSQL *connect = mysql_init(NULL);
db.mysql = mysql_init(NULL);
printf("HOST %s\n", db.host);
if(!mysql_real_connect(db.mysql, db.host, db.user, db.pass, db.name, 0, 0, 0))
{
printf("Conection error : %s\n", mysql_error(db.mysql));
exit(1);
}
return db.mysql;
}
MYSQL_RES* mysql_perform_query(MYSQL *connect, char *command)
{
if(mysql_query(connect, command))
{
printf("MySQL query error : %s\n", mysql_error(connect));
exit(1);
}
return mysql_use_result(connect);
}
......................... .........................
if i try use mysql function in 如果我尝试在中使用mysql函数
int some_func()
{
database_t *db = malloc(sizeof(database_t));
db->mysql = mysql_connection_setup();
return 0;
}
After compile il see some warnings. 编译后,请参阅一些警告。
warning: implicit declaration of function 'mysql_connection_setup' [-Wimplicit-function-declaration] db->mysql = mysql_connection_setup(); 警告:函数'mysql_connection_setup'的隐式声明[-Wimplicit-function-declaration] db-> mysql = mysql_connection_setup(); warning: assignment makes pointer from integer without a cast [-Wint-conversion] db->mysql = mysql_connection_setup(); 警告:赋值使指针从整数开始而没有强制转换[-Wint-conversion] db-> mysql = mysql_connection_setup();
What me do whith it? 我怎么办呢?
The warnings say that the compiler hasn't seen any declaration for mysql_connection_setup()
when you first use it. 警告说,当您初次使用mysql_connection_setup()
时,编译器未看到任何声明。 So, the compiler declared one implcitly with int
return type which conflicts with your actual function. 因此,编译器隐式声明了一个int
返回类型,该类型与您的实际函数冲突。 (Note that the "implicit int" rule has been removed from the C standard since C99). (请注意,自C99以来,“隐式int”规则已从C标准中删除)。
So, provide a declaration at the top of your source file: 因此,在源文件的顶部提供一个声明:
MYSQL* mysql_connection_setup(database_t db);
Or declare it as extern
in a header file and include that header file in your source files if you are using mysql_connection_setup()
is in other source file(s). 或者,如果在其他源文件中使用mysql_connection_setup()
则在头文件中将其声明为extern
并将其包含在源文件中。
con_setup.h: con_setup.h:
#ifndef CON_SETUP_H
#define CON_SETUP_H
extern MYSQL* mysql_connection_setup(database_t db);
#endif
and include con_setup.h
in your C files. 并在C文件中包含con_setup.h
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.