Re: passing values to functions - question repeated



Hi,

Shiraz Baig <shiraz_baig yahoo com> writes:

>   I am going to repeat my question and try to clarify
> it further. 
> 
> We know that in any program, whenever we call a
> function, we have to pass some data to that
> function and then only that function can use that
> data.
> 
> In my program (that I posted earlier), The function to
> be called is:
> -----------------------------------
> void hello( GtkWidget *widget,
>             gpointer   data )
> {
>     g_print ("Hello World\n");
> }
> -----------------------------------
> On the other hand, In the main() we are calling this
> function as follows:
> 
>     gtk_signal_connect (GTK_OBJECT (button),"clicked",
>                         GTK_SIGNAL_FUNC (hello),
>                          NULL);
> 
> 
> Now my question is as follows: 
> 
> We are passing NULL as data to the function
> "hello". Yet, hello function (as declared above) is
> showing that it has been passed two arguments, the
> widget and the gpointer.

it shows that it expects two parameters and indeed it
is called with two parameters, the GtkButton widget
and the pointer you specified when connecting the 
signal, which is NULL in your example.

> Why doesn't the compiler complain that you are passing
> NULL to the function and then you are trying to use
> arguments in the function?

NULL is a perfectly valid pointer value (just don't try
to dereference it). I have the impression I'm still 
missing your point...


Salut, Sven



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]