digitalmars.D - My ignorance, or a bug - help please
- Steve Teale (28/28) Oct 07 2011 I was converting something that was a class to a struct, and ran into th...
- mta`chrono (25/25) Oct 07 2011 -------------- mysql.d ----------------
- travert phare.normalesup.org (Christophe) (6/38) Oct 07 2011 I don't know what is going one, but putting a MYSQL object in Connection...
- mta`chrono (16/16) Oct 07 2011 If you don't need the internal data of struct MYSQL and you don't want
- Steve Teale (3/3) Oct 07 2011 The empty struct is a red herring. I cut mysql.d down to the bare minimu...
- Jacob Carlborg (5/9) Oct 07 2011 The correct way to do this is to declare an opaque struct, just as in C:
I was converting something that was a class to a struct, and ran into this (minimized as much as possible): import mysql; // The import mysql.d for the test contains only: /* extern (C): struct MYSQL{} MYSQL* mysql_init(MYSQL* mysql); */ // If I put this stuff in-line the error does not happen struct Connection { MYSQL _mysql; ~this() { } this(int dummy = 0) { mysql_init(&_mysql); } } // dmd -c mysqld.d (2.055 - Ubuntu) // // Error: can only initialize const member _mysql inside constructor // Error: this is not mutable Does anyone have any idea what's going on? Thanks Steve
Oct 07 2011
-------------- mysql.d ---------------- extern (C): struct MYSQL{} MYSQL* mysql_init(MYSQL* mysql); -------------- main.d ----------------- import mysql; struct Connection { MYSQL _mysql; ~this() { } this(int dummy = 0) { mysql_init(&_mysql); } } void main() { Connection con1; Connection *con2 = new Connection(123); } ------------------------------------- dmd main.d mysql.d -L-lmysqlclient works with DMD64 D Compiler v2.056
Oct 07 2011
Steve Teale , dans le message (digitalmars.D:146210), a écrit :I was converting something that was a class to a struct, and ran into this (minimized as much as possible): import mysql; // The import mysql.d for the test contains only: /* extern (C): struct MYSQL{} MYSQL* mysql_init(MYSQL* mysql); */ // If I put this stuff in-line the error does not happen struct Connection { MYSQL _mysql; ~this() { } this(int dummy = 0) { mysql_init(&_mysql); } } // dmd -c mysqld.d (2.055 - Ubuntu) // // Error: can only initialize const member _mysql inside constructor // Error: this is not mutable Does anyone have any idea what's going on?I don't know what is going one, but putting a MYSQL object in Connection after having defined MYSQL as a dummy empty extern C struct does not seem to be a good idea. -- Christophe
Oct 07 2011
If you don't need the internal data of struct MYSQL and you don't want to care about. Then just keep some reference in your program. alias void MYSQL; alias void MYSQL_RES; and then only use MYSQL* and pass it to every function. struct Connection { MYSQL* _mysql; ~this() { } this(int dummy = 0) { mysql_init(_mysql); } }
Oct 07 2011
The empty struct is a red herring. I cut mysql.d down to the bare minimum to help isolate the bug. I get exactly the same error with the complete mysql.d
Oct 07 2011
On 2011-10-07 11:55, mta`chrono wrote:If you don't need the internal data of struct MYSQL and you don't want to care about. Then just keep some reference in your program. alias void MYSQL; alias void MYSQL_RES;The correct way to do this is to declare an opaque struct, just as in C: struct MYSQL; -- /Jacob Carlborg
Oct 07 2011