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

Reply via email to