digitalmars.D.learn - C structs
- Johann Lermer (34/34) Jun 20 2014 Hi,
- Kagamin (2/3) Jun 20 2014 it's an init value for the struct; in D all data is initialized.
- Dicebot (4/4) Jun 20 2014 By D specification you are always required to compiled all
- Johann Lermer (7/7) Jun 20 2014 Agreed, but I assumed, that since all definitions in cairo.d are
- Dicebot (5/12) Jun 20 2014 D requires that all variable are default-initialized, extern or
- Artur Skawina via Digitalmars-d-learn (6/10) Jun 21 2014 If i were to guess: the compiler optimizes the init-blitting into
Hi, I'm fiddling around with cairo (downloaded fromhttps://github.com/D-Programming-Deimos/cairo) and I stumbled over this problem: (file rectandmatrix.d) ---- import deimos.cairo.cairo; void main () { cairo_rectangle_int_t rect; cairo_matrix_t matrix; } ---- Compiling that with 'dmd rectandmatrix' fails with this error: rectandmatrix.o: In function `_Dmain': rectandmatrix.d:(.text._Dmain+0x18): undefined reference to `_D6deimos5cairo5cairo14cairo_matrix_t6__initZ' collect2: error: ld returned 1 exit status --- errorlevel 1 The rectangle is OK - no error there. The matrix however, produces the error. The difference between both is that cairo_rectangle_int_t is a struct containing integers, and cairo_matrix_t contains doubles. I can, however, compile like that: 'dmd rectandmatrix deimos/cairo/cairo.d' (deimos being in a subdir of the working directory) then cairo.d is compiled as well and linked to the code. So, my questions are: 1) Why do I have to compile and link cairo.d - it's only an definition file for C code and IMHO there shouldn't be any need to compile cairo.d at all. 2) Why ist a struct containing only integers handled so differently from a struct holding doubles? Thanks
Jun 20 2014
On Friday, 20 June 2014 at 10:51:20 UTC, Johann Lermer wrote:`_D6deimos5cairo5cairo14cairo_matrix_t6__initZ'it's an init value for the struct; in D all data is initialized.
Jun 20 2014
By D specification you are always required to compiled all imported modules, it does not matter if those contain only definitions. Some of implicitly generated symbols (like T.init) will be in their object files.
Jun 20 2014
Agreed, but I assumed, that since all definitions in cairo.d are defined as extern (System), (same happens with extern (C), btw.), I would have expected, that D does not implicitly generate initialisation functions. So, why is there no init routine for the rectangle? There's only one for the matrix.
Jun 20 2014
On Friday, 20 June 2014 at 12:17:22 UTC, Johann Lermer wrote:Agreed, but I assumed, that since all definitions in cairo.d are defined as extern (System), (same happens with extern (C), btw.), I would have expected, that D does not implicitly generate initialisation functions.D requires that all variable are default-initialized, extern or not -> T.init is necessary.So, why is there no init routine for the rectangle? There's only one for the matrix.That needs actually building deimos cairo and checking symbols in object files so I will do as soon as have a bit more spare time ;)
Jun 20 2014
On 06/20/14 14:42, Dicebot via Digitalmars-d-learn wrote:On Friday, 20 June 2014 at 12:17:22 UTC, Johann Lermer wrote:If i were to guess: the compiler optimizes the init-blitting into a memset(-equivalent) when all the members are default initted to zero; D's doubles are initialized to NaN, so this optimization is not happening when a struct contains such fields. arturSo, why is there no init routine for the rectangle? There's only one for the matrix.That needs actually building deimos cairo and checking symbols in object files so I will do as soon as have a bit more spare time ;)
Jun 21 2014