> Stephan Beal wrote: >> 2012/2/3 Jorge Eliécer Osorio Caro <jorgeliecer.osorio at gmail.com> >> >> > *ppVTab = (sqlite3_vtab*) nr; >> > ((sqlite3_vtab*) nr)->zErrMsg = NULL; >> > >> >> Please try changing those to the variants from my previous post. i'm not >> 100% convinced that that cast is strictly legal in C++. > > It will work with all the C/C++ implementations I've seen. However, it > would be better, and more informative, and ultimately more robust, to > change this code: > typedef struct NiuRoutingStruct { > sqlite3_vtab vtab; > } NiuRouting; > to this: > struct NiuRouting : public sqlite3_vtab vtab { > ... // your implementation, eventually > }; > > This way, the casting is unnecessary and any pointer offsetting will be > done correctly.
Just for my curiosity: Is the above really equivalent to the C definition like: typedef struct NiuRoutingStruct { sqlite3_vtab vtab; ... // your implementation, eventually } NiuRouting; ? Reason I'm asking: sqlite uses a pointer to that structure to access "sqlite3_vtab vtab" member - in machine code that would be memory offset 0, all other private members start at +sizeof(sqlite3_vtab)+optional alignment. Now, I'm wondering if a c++ style of inheritance is defined in the same way - Note that sqlite relies on that, or better say "the compiler that produced the sqlite machine code relies on that". Just in case the c++ compiler rearrange the byte offset differently it will crash rights away, I think. Thanks. Marcus > > The use of C-style casts in C++ is bad practice. Use static_cast where > you can. The problem with C-style casting is that it can become a > reinterpret_cast when that is going to produce problems. > > -- > Larry Brasfield > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users