[Inkscape- Devel][Recolor] Default Arguments Compiling Error
Hi, I have been trying to write a function with a default argument.
The function: void recolor_wheel_nodes_init(GtkWidget *widget , int obj_list_size = RECOLOR_MAX_OBJECTS ) { ..... }
This gives the following error: expected ';', ',' or ')' before '=' token
Aren't default arguments allowed in GTK ? I bet I've seen them at a few places in the codebase before.
On Jul 25, 2013, at 11:44 PM, Arshdeep Singh wrote:
Hi, I have been trying to write a function with a default argument.
The function: void recolor_wheel_nodes_init(GtkWidget *widget , int obj_list_size = RECOLOR_MAX_OBJECTS ) { ..... }
This gives the following error: expected ';', ',' or ')' before '=' token
Aren't default arguments allowed in GTK ? I bet I've seen them at a few places in the codebase before.
Default arguments go in the declaration, not definition of a function. I think this is the first issue you're hitting up against. (BTW, the "void" should not end up on a line by itself)
Next is that C++ allows for default arguments, but the GTK+ init functions do not. The GTK+ type system is pure C and has expectations as such. If you are expecting to use this as a GTK+ init function, the the GTK+ system probably will not use the default.
At compile time, what happens is that the compiler acts as if you explicitly had typed recolor_wheel_nodes_init(widget, RECOLOR_MAX_OBJECTS);
I did put the default argument in the declaration only too. I remember trying the three cases: 1.) Default argument in declaration only 2.) Default argument in definition only 3.) Default argument in declaration and definition both.
All three cases gave the same error. In the third case the error was repeated twice.
On Fri, Jul 26, 2013 at 12:22 PM, Jon Cruz <jon@...18...> wrote:
On Jul 25, 2013, at 11:44 PM, Arshdeep Singh wrote:
Hi, I have been trying to write a function with a default argument.
The function: void recolor_wheel_nodes_init(GtkWidget *widget , int obj_list_size =
RECOLOR_MAX_OBJECTS ) { ..... }
This gives the following error: expected ';', ',' or ')' before '=' token
Aren't default arguments allowed in GTK ? I bet I've seen them at a few
places in the codebase before.
Default arguments go in the declaration, not definition of a function. I think this is the first issue you're hitting up against. (BTW, the "void" should not end up on a line by itself)
Next is that C++ allows for default arguments, but the GTK+ init functions do not. The GTK+ type system is pure C and has expectations as such. If you are expecting to use this as a GTK+ init function, the the GTK+ system probably will not use the default.
At compile time, what happens is that the compiler acts as if you explicitly had typed recolor_wheel_nodes_init(widget, RECOLOR_MAX_OBJECTS);
2013/7/26 Arshdeep Singh <moduli16@...400...>:
I did put the default argument in the declaration only too. I remember trying the three cases: 1.) Default argument in declaration only 2.) Default argument in definition only 3.) Default argument in declaration and definition both.
All three cases gave the same error. In the third case the error was repeated twice.
If you are trying to write this in the gimpcolorwheel.c file, then it's a C file and as such is compiled by the C compiler, not the C++ compiler. Plain C does not have default arguments. You can fix this by converting it to a C++ file - use the 'bzr mv' command to change the extension. But a far better idea is to leave this file alone, and write your own GObject class InkRecolorWheel that derives from GimpColorWheel. This way it will be much easier to update GimpColorWheel from GIMP sources in the future.
Regards, Krzysztof
participants (3)
-
Arshdeep Singh
-
Jon Cruz
-
Krzysztof Kosiński