On Feb 19, 2005, at 4:07 PM, Gert Cuykens wrote:

On Sat, 19 Feb 2005 02:57:53 -0700, Chad Leigh -- Shire. Net LLC
<[EMAIL PROTECTED]> wrote:

On Feb 19, 2005, at 2:51 AM, Gert Cuykens wrote:

On Thu, 17 Feb 2005 13:17:51 +0100, Hubert Sokołowski
<[EMAIL PROTECTED]> wrote:
On Thu, 17 Feb 2005 13:05:43 +0100
Gert Cuykens <[EMAIL PROTECTED]> wrote:

static void callback( GtkWidget *widget, gpointer   data ){
    g_print ("Hello again - %s was pressed\n", (gchar *) data);
}

why do they put () around gchar ?
why can it not be gchar *data ?

You should learn some more about programming in C before you start writing GTK apps.

hs

Does anybody want to explain what the () thingies are around gchar * ?



It is a typecast -- coercing "data" to be of type (gchar *) to the compiler when matching parameter types at compiler time.

Chad


lol :) I wish you could see the expression on my face while reading it :)


Why can i not do this ?

g_print ("Hello again - %s was pressed\n", gchar *data);
or this
gchar *data;
g_print ("Hello again - %s was pressed\n", *data);
or this
gchar *data;
g_print ("Hello again - %s was pressed\n", data);

What does coercing mean ?
Why does the compiler have to match parameters ?

I'll let you look up the answers above in C reference manuals (and C++ ones for by reference parameters). However, the answer to "Why" is best known to Kernighan and Ritchie <http://cm.bell-labs.com/cm/cs/cbook/>


C is (now) a strongly typed language and this type checking is done at compile time in order to try and help you reduce errors.


PS what is the difference between ?

Assuming the following declaration

gpointer        data;

data is a pointer to some kind of structure

A=*data

this is the data itself, ie, the pointer is dereferenced

A=data

this is the pointer to the data

A=&data

this is a kind of double indirection -- this is a reference to the pointer to the data. I believe this sort of notation for a reference first came from Bjarne Stroustrop or however he spells it -- the "father" of C++


I am not a C nor C++ expert. I long ago stopped doing C++ and my C is mostly confined to Objective-C now-a-days. Best to get the latest K&R C book and a good C++ book to answer your questions.

best
Chad

_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to