0

I made the assumption that int args passed for double parameters would be converted to doubles. For example

I am calling: make_line(root, "hi", 5,5,50,50);

on:

GooCanvasItem * make_line(GooCanvasItem * parent, char * name, gdouble x1, gdouble y1, gdouble x2, gdouble y2)
{
    printf("from make line: %f %f %f %f\n", x1, y1, x2, y2);
    //...
}

the printf produces:

from make line: 0.000000 0.000000 0.000000 0.000000

when I call it with

make_line(root, "hi", 5.0,5.0,50.0,50.0);

it gives the correct output.

Changing gdouble to double doesn't seem to fix the problem.

mihajlv
  • 2,275
  • 4
  • 36
  • 59

1 Answers1

3

a (5) won't be converted into 0.

I believe you are using %d in your printf instead of %f for printing double values. Turn on the compiler warnings when you compile your code.

Use -Wformat option of gcc.

P.P
  • 117,907
  • 20
  • 175
  • 238
  • @Ayub: In C standard, `%lf` -> `scanf`. – md5 Oct 25 '12 at 17:13
  • 4
    @Ayub Nope :) See: [Correct format specifier for double](http://stackoverflow.com/questions/4264127/correct-format-specifier-for-double-in-printf) – P.P Oct 25 '12 at 17:14
  • Thanks for the clarification. :) Good that many eyes are there to fix little mistakes. :D – Ayub Oct 25 '12 at 17:15
  • @mihajlv What's `gdouble`? how is it defined? – P.P Oct 25 '12 at 17:31
  • @mihajlv `Changing gdouble to double doesn't seem to fix the problem.` This can't be true. Here's the simplified demo: http://ideone.com/Bwan2d – P.P Oct 25 '12 at 17:39
  • @KingsIndian I know, it is wierd gdouble is just the c double used by glib, I think it has to do something with the glib library. – mihajlv Oct 25 '12 at 17:47