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@...1656...8...> 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);





--
Arshdeep Singh
Third Year, Computer Engineering
Delhi Technological University
Ph: +91-9654115614
https://sites.google.com/site/adsingh1729/home