Re: [sqlite] GCC give a warning while passing a struct as the, user data to the callback function of sqlite3_exec()
Enrique Ramirez wrote: > I noticed what you mean (to reply to my own post). I just noticed the > original subject and this thread's subject are different: > > (original) [sqlite] GCC give a warning while passing a struct as the > user data to the callback function of sqlite3_exec() > (this thread) [sqlite] GCC give a warning while passing a struct as > the, user data to the callback function of sqlite3_exec() > > Notice the comma? Maybe you modified it by mistake. Gmail uses > subjects to thread messages. Oh, I didn't notice that I have add an ',' in the second mail. Thank you for replying. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] GCC give a warning while passing a struct as the, user data to the callback function of sqlite3_exec()
Enrique Ramirez wrote: > Looking at your address I can see you also use gmail. Threading for > this message is working fine for me. Are you using the web client or > an external mail program? > In fact, I'm using thunderbird, but it may doesn't matters. When i subscribed, I turn digest mode on, may be it cause the issues. Now I have turn it off, seems that my reply before has been list correctly. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] GCC give a warning while passing a struct as the, user data to the callback function of sqlite3_exec()
Greetings, > As Michael Knigge has suggested, you may just rename the parameter to > something else and then have something like > >MyStruct* data = (MyStruct*)foo; > > as the first line in your callback() function. Got it. Sorry but I make a mistake before, the '3rd argument' ought to be '4th argument', so the question should be: It means that while passing the 4th argument in sqlite3_exec(), the argument has been casted to void* ? However, thank you for your explanation for the callback function. I have another problem now, it sounds silly but... Each time I reply, it create a new topic, but not listing the reply under the original mail. How to make my reply mail is exactly list under the original mail somebody posted? ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] GCC give a warning while passing a struct as the, user data to the callback function of sqlite3_exec()
Thank you, Markus! > Simply change the type of the first argument to your callback function > to void* and the problem should go away. Of course you'll then have to > cast back to MyStruct* inside callback() to actually use the value. It works. Just ((MyStruct *) data)->x looks strange. > The problem here is the type of your callback() function. By declaring > the first argument to it as MyStruct*, rather than void* as in the > function pointer type of the 3rd argument to sqlite3_exec(), you're > creating an incompatible function pointer type. It means that while passing the 3rd argument in sqlite3_exec(), the argument has been casted to void* ? BTW: It is the first time I use mail list, hope I'm replying correctly. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] GCC give a warning while passing a struct as the user data to the callback function of sqlite3_exec()
I declare a struct and pass it as the 4th argument of sqlite3_exec(), and define the 1st argument of callback function a pointer to this kind of struct. while compiling, GCC give a warning like this: ae.c: In function ‘main’: ae.c:56: warning: passing argument 3 of ‘sqlite3_exec’ from incompatible pointer type however, the program runs well. What may causing the warning? what should i do to get rid of this warning. Thanks! Here is an simple example: #include #include #include typedef struct { int x; int y; }MyStruct; static int callback(MyStruct *data, int argc, char **argv, char **azColName){ int i; printf ("%d, %d\n", data->x, data->y); for(i=0; ix = 1; data->y = 2; if( argc!=3 ){ fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]); exit(1); } rc = sqlite3_open(argv[1], ); if( rc != SQLITE_OK){ fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); sqlite3_close(db); exit(1); } rc = sqlite3_exec(db, argv[2], callback, data, ); if( rc!=SQLITE_OK ){ fprintf(stderr, "SQL error: %s\n", zErrMsg); sqlite3_free(zErrMsg); } sqlite3_close(db); free (data); return 0; } ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users