dimanche 31 août 2008

Trying to describe a bug

Something does not compile.
Most of the time, your own fault!

Once in a lifetime: a bug in the language.
Here is one:
but how difficult to describe it, because it is a weird combination i used, probably did it the first time ever.....

in C:

first i made a struct, just a POINT, two struct members
then declared a global instance of this struct
then i tested the sin function with a number (hardcoded) like .787878788 inside iprinf
then i tested the sin function with a structmember

the code is totally stripped:

#include --the math lib--
//this can be in a header file
typedef struct point{
double x;
double y;
}POINT;

//-------------------------

//source file:
//include header file

POINT q1;
//this global does not functions in combination with iprintf
//without iprintf no problem

int main() {

q1.x = 0.78787878787878;
q1.y = 0.686868686868686;

iprintf("point %d\n", (int) ( 100*sin( 0.12345 ) ) ) ;
iprintf("point %d\n", (int) ( 100*sin( q1.x ) ) ) ;
//multiply by 100 because it should run on the nds, without floats

return 0;
}

compile error!

declare this struct instance locally: no compile error

without the iprintf (global struct instance again): no compile error.
programming sneaky: global POINT q, local pointer to q, then iprint and sin of this pointer:
compile error!

the same in Cpp: no compile error.

ok tried everything, i agree: this is a strange case! But it seems to be real.