Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 19 Feb 2005 16:16:33 -0700
From:      Chad Leigh -- Shire.Net LLC <chad@shire.net>
To:        Gert Cuykens <gert.cuykens@gmail.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: c++
Message-ID:  <8a07eb15461541c47c5e26f7a803299a@shire.net>
In-Reply-To: <ef60af0905021915074e5d2929@mail.gmail.com>
References:  <ef60af09050219015116024f83@mail.gmail.com> <5b8472dd5925a0b0b59f15cd9f8e15f3@shire.net> <ef60af0905021915074e5d2929@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

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
> <chad@shire.net> wrote:
>>
>> On Feb 19, 2005, at 2:51 AM, Gert Cuykens wrote:
>>
>>> On Thu, 17 Feb 2005 13:17:51 +0100, Hubert Soko=A9=A9owski
>>> <h.sokolowski@wsisiz.edu.pl> wrote:
>>>> On Thu, 17 Feb 2005 13:05:43 +0100
>>>> Gert Cuykens <gert.cuykens@gmail.com> 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 *=20=

>>> ?
>>>
>>
>> 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=20=

> :)
>
> 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++=20=

ones for by reference parameters). However, the answer to "Why" is best=20=

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=20=

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=3D*data

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

>  A=3Ddata

this is the pointer to the data

>  A=3D&data

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

I am not a C nor C++ expert.  I long ago stopped doing C++ and my C is=20=

mostly confined to Objective-C now-a-days.  Best to get the latest K&R=20=

C book and a good C++ book to answer your questions.

best
Chad



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?8a07eb15461541c47c5e26f7a803299a>