Reputation: 3
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
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(); warning: assignment makes pointer from integer without a cast [-Wint-conversion] db->mysql = mysql_connection_setup();
What me do whith it?
Upvotes: 0
Views: 606
Reputation: 121427
The warnings say that the compiler hasn't seen any declaration for mysql_connection_setup()
when you first use it. So, the compiler declared one implcitly with int
return type which conflicts with your actual function. (Note that the "implicit int" rule has been removed from the C standard since C99).
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).
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.
Upvotes: 3