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()
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. Hope this helps, > On Tue, Aug 19, 2008 at 8:58 AM, Midmay <[EMAIL PROTECTED]> wrote: >> 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 >> > > > > -- > // -- > Enrique Ramirez Irizarry > Lead Developer > Indie Code Labs > http://www.indiecodelabs.com > -- // -- Enrique Ramirez Irizarry Lead Developer Indie Code Labs http://www.indiecodelabs.com ___ 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()
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? On Tue, Aug 19, 2008 at 8:58 AM, Midmay <[EMAIL PROTECTED]> wrote: > 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 > -- // -- Enrique Ramirez Irizarry Lead Developer Indie Code Labs http://www.indiecodelabs.com ___ 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()
Greetings, > It works. Just ((MyStruct *) data)->x looks strange. 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. In fact I believe in C implicit casts from void* are allowed, so the explicit cast on the right is probably unnecessary. However, C++ compilers definitely do not allow implicit casts from void*, so you might as well put it, just in case. > It means that while passing the 3rd argument in sqlite3_exec(), the > argument has been casted to void* ? The 3rd argument is "callback", it's expected to be of type int (*callback)(void*, int, char**, char**) your original callback however had a different type, namely int (*callback)(MyStruct*, int, char**, char**) I'm not exactly sure what the semantics for function pointer casts are, if there are any at all. To (maybe) answer your question, casts from pointer types to void* are always allowed, that is why your 4th argument of type MyStruct* is accepted without any complaints, even though sqlite3_exec() expects a void* there. The warning had nothing to do with the 4th argument ("first argument to callback") at all, only with the 3rd argument ("callback function"). The program happens to run correctly because the internal representation, etc. of the function happens to be the same with both parameter types (MyStruct* and void*), but that is undefined behavior and it might well crash on a different platform or with a different compiler (although I'd guess in this particular case it's probably rather unlikely). Regards, -- Markus Thiele ___ 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
Re: [sqlite] GCC give a warning while passing a struct as the user data to the callback function of sqlite3_exec()
> however, the program runs well. What may causing the warning? what > should i do to get rid of this warning. The warning is produced because your callback() isn't int callback(void *, int, char **, char **); try this: int callback(void *foo, int argc, char **argv, char **azColName) { MyStruct *data = (MyStruct *)foo; ... } haven't checked, but this should blow away the warning Bye, Michael ___ 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, > 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 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. > however, the program runs well. What may causing the warning? what > should i do to get rid of this warning. 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. Hope this helps, -- Markus Thiele ___ 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