Ask a Question related to FreeBSD, Design and Development.
-
Gert Cuykens #1
c++
On Thu, 17 Feb 2005 13:17:51 +0100, Hubert Sokołowski
<h.sokolowski@wsisiz.edu.pl> wrote:Does anybody want to explain what the () thingies are around gchar * ?> 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
Gert Cuykens Guest
-
Chad Leigh -- Shire.Net LLC #2
Re: c++
On Feb 19, 2005, at 2:51 AM, Gert Cuykens wrote:
It is a typecast -- coercing "data" to be of type (gchar *) to the> On Thu, 17 Feb 2005 13:17:51 +0100, Hubert Soko©©owski
> <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 * ?
>
compiler when matching parameter types at compiler time.
Chad
Chad Leigh -- Shire.Net LLC Guest
-
Gert Cuykens #3
Re: c++
On Sat, 19 Feb 2005 02:57:53 -0700, Chad Leigh -- Shire. Net LLC
<chad@shire.net> wrote:lol :) I wish you could see the expression on my face while reading it :)>
> On Feb 19, 2005, at 2:51 AM, Gert Cuykens wrote:
>>> > On Thu, 17 Feb 2005 13:17:51 +0100, Hubert Sokołowski
> > <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 * ?
> >
> It is a typecast -- coercing "data" to be of type (gchar *) to the
> compiler when matching parameter types at compiler time.
>
> Chad
>
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 ?
PS what is the difference between ?
A=*data
A=data
A=&data
Gert Cuykens Guest
-
Steven #4
Re: c++
Gert Cuykens wrote:
You should really get a book about programming or ask your teacher.>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:
>>
>>
>>>>It is a typecast -- coercing "data" to be of type (gchar *) to the>>>On Thu, 17 Feb 2005 13:17:51 +0100, Hubert Sokołowski
>>><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 * ?
>>>
>>>
>>>
>>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 ?
>
>PS what is the difference between ?
> A=*data
> A=data
> A=&data
>_______________________________________________
>freebsd-questions@freebsd.org mailing list
>[url]http://lists.freebsd.org/mailman/listinfo/freebsd-questions[/url]
>To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"
>
>
These are basic questions about c/c++ programming.
But to answer your question: You need to cast the data, so you can hand
data of different but matching type to the function. (eg. you have a
pointer to int but the function expects a plain pointer)
Steven
Steven Guest
-
Chad Leigh -- Shire.Net LLC #5
Re: c++
On Feb 19, 2005, at 4:07 PM, Gert Cuykens wrote:
I'll let you look up the answers above in C reference manuals (and C++> 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©©owski
>>> <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 *
>>> ?
>>>
>> 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 ?
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.
Assuming the following declaration>
> PS what is the difference between ?
gpointer data;
data is a pointer to some kind of structure
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> A=&data
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
Chad Leigh -- Shire.Net LLC Guest
-
Anthony Atkielski #6
Re: c++
Gert Cuykens writes:
Telling the compiler to disregard mismatches between data types.> What does coercing mean ?
Normally, if you put an integer in a program where a character pointer
is required, the compiler will complain. If you use a cast to coerce
the type of the integer to a character pointer, the compiler will let it
pass, and will treat the integer as a pointer (whether it really
contains a pointer or not).
To help avoid errors in coding, the compiler makes sure that the type of> Why does the compiler have to match parameters ?
a variable matches what is expected in certain situations.
The contents of the memory location pointed to by data is copied to A.> PS what is the difference between ?
> A=*data
The value of data is copied to A.> A=data
The address in memory of data is copied to A.> A=&data
--
Anthony
Anthony Atkielski Guest
-
Gert Cuykens #7
Re: c++
On Sun, 20 Feb 2005 00:17:31 +0100, Anthony Atkielski
<atkielski.anthony@wanadoo.fr> wrote:So if data is declared as a gchar *data; for example, then the value>> > A=*data
> The contents of the memory location pointed to by data is copied to A.
>>> > A=data
> The value of data is copied to A.
>>> > A=&data
> The address in memory of data is copied to A.
>
> --
> Anthony
>
of data is a memory adress right ? So if A=data; and B=&data; then A
and B are exactly the same result right ?
Now why would anybody want a gchar when a integer is needed ? That is
just making it more complicated then it already is?
Gert Cuykens Guest
-
Scott Mitchell #8
Re: c++
On Sun, Feb 20, 2005 at 08:41:30AM +0100, Gert Cuykens wrote:
No. A is a 'pointer to gchar' (or gchar*) and B is a 'pointer to pointer>
> So if data is declared as a gchar *data; for example, then the value
> of data is a memory adress right ? So if A=data; and B=&data; then A
> and B are exactly the same result right ?
to gchar' (or gchar**). The '&data' syntax means 'the address of the data
variable', ie. the address of a gchar*, whereas data itself contains the
address of a gchar.
Because the code in question deals with gchars (whatever they are) not> Now why would anybody want a gchar when a integer is needed ? That is
> just making it more complicated then it already is?
integers? They won't necessarily be the same thing on different
architectures, or even different compilers on the same architecture. Also,
the type is called 'gchar' presumably because it logically holds some kind
of character data, whereas an integer variable holds an integer. Calling
them different things in the code helps to make it clear what the
programmer's intention is, even if the two types happen to have the same
representation on a given machine/compiler.
In any case, this stuff really has nothing to do with FreeBSD - you should
be asking these questions in a C/C++ programming group.
Cheers,
Scott
--
================================================== =========================
Scott Mitchell | PGP Key ID | "Eagles may soar, but weasels
Cambridge, England | 0x54B171B9 | don't get sucked into jet engines"
scott at fishballoon.org | 0xAA775B8B | -- Anon
Scott Mitchell Guest
-
Gert Cuykens #9
Re: c++
On Sun, 20 Feb 2005 12:47:50 +0000, Scott Mitchell
<scott+lists.freebsd@fishballoon.org> wrote:Thx i think i understand now :)> On Sun, Feb 20, 2005 at 08:41:30AM +0100, Gert Cuykens wrote:>> >
> > So if data is declared as a gchar *data; for example, then the value
> > of data is a memory adress right ? So if A=data; and B=&data; then A
> > and B are exactly the same result right ?
> No. A is a 'pointer to gchar' (or gchar*) and B is a 'pointer to pointer
> to gchar' (or gchar**). The '&data' syntax means 'the address of the data
> variable', ie. the address of a gchar*, whereas data itself contains the
> address of a gchar.
>>> > Now why would anybody want a gchar when a integer is needed ? That is
> > just making it more complicated then it already is?
> Because the code in question deals with gchars (whatever they are) not
> integers? They won't necessarily be the same thing on different
> architectures, or even different compilers on the same architecture. Also,
> the type is called 'gchar' presumably because it logically holds some kind
> of character data, whereas an integer variable holds an integer. Calling
> them different things in the code helps to make it clear what the
> programmer's intention is, even if the two types happen to have the same
> representation on a given machine/compiler.
>
> In any case, this stuff really has nothing to do with FreeBSD - you should
> be asking these questions in a C/C++ programming group.
>
> Cheers,
>
> Scott
>
> --
PS Freebsd source is c++ right ? So you could also call this the free
c++ question mailing list :)
Also about all the get a c++ book comments, i tryed that once but when
i ask the book a question, it doesnt say anything back. It only makes
noises when you flaper the pages trough the wind.
By the way if somebody passing your street asking for direction you
dont answer get a map either right ?
Gert Cuykens Guest
-
Gert Cuykens #10
Re: c++
On Sun, 20 Feb 2005 16:15:43 +0100, Daniel S. Haischt
<me@daniel.stefan.haischt.name> wrote:I did that but they give me the get book and ask somebody els answer.> Gert Cuykens,
>
> I would suggest to post such questions to [email]gtk-list@gnome.org[/email],
> because IIRC you are trying to code a GTK app ...
>
> Additionally I would suggest to learn C/C++ first to get a better
> understanding of the whole language structure. Or at least please
> join the c# IRC channel at irc.freenode.net to ask such questions,
> it's quite annoying to see them on a list which is dedicated to an
> UNIX OS.
Gert Cuykens Guest
-
Scott Mitchell #11
Re: c++
On Sun, Feb 20, 2005 at 04:34:45PM +0100, Gert Cuykens wrote:
FreeBSD is almost entirely written in C, although there are a few bits of>
> Thx i think i understand now :)
>
> PS Freebsd source is c++ right ? So you could also call this the free
> c++ question mailing list :)
C++ under /usr/src.
This is a list for questions about FreeBSD, not basic C++ programming.
Get a better book? Sign up for a C/C++ course?> Also about all the get a c++ book comments, i tryed that once but when
> i ask the book a question, it doesnt say anything back. It only makes
> noises when you flaper the pages trough the wind.
No, but you didn't ask me, you asked maybe 10,000 people you've never met,> By the way if somebody passing your street asking for direction you
> dont answer get a map either right ?
most of whom don't live in the same town as either of us...
Followups redirected to -chat.
Scott
--
================================================== =========================
Scott Mitchell | PGP Key ID | "Eagles may soar, but weasels
Cambridge, England | 0x54B171B9 | don't get sucked into jet engines"
scott at fishballoon.org | 0xAA775B8B | -- Anon
Scott Mitchell Guest
-
Bill Moran #12
Re: c++
Gert Cuykens <gert.cuykens@gmail.com> wrote:
No and no.> PS Freebsd source is c++ right ? So you could also call this the free
> c++ question mailing list :)
That's very funny. Perhaps you should be a comedian instead of a> Also about all the get a c++ book comments, i tryed that once but when
> i ask the book a question, it doesnt say anything back. It only makes
> noises when you flaper the pages trough the wind.
programmer.
Those responses are NOT rude, as you seem to imply. The simple fact> By the way if somebody passing your street asking for direction you
> dont answer get a map either right ?
is that your question indicates that you are lacking some _basic_
knowledge required to understand C++ coding. The response is an
hostest attempt to make you understand that your _BEST_ course of
action at this level of learning is to get a good book and read it.
Personally, I recommend _The_C_Programming_Language_ by Kernighan and
Richie. It's an excellent read.
We could be very careless and just _tell_ you the answer, but we're
better people than that. We recognize the level of learning that you're
at (because we've all been there) and are attempting to help you along.
--
Bill Moran
Potential Technologies
[url]http://www.potentialtech.com[/url]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (FreeBSD)
iD8DBQFCGLhuYOm/CGAEZUARAi9pAKCub6SZSzRttpd3wmtX4/1U3faeggCgwm+y
0HFzZdX+XEkdQLtu0WvglzU=
=Hcr3
-----END PGP SIGNATURE-----
Bill Moran Guest
-
Chris Hodgins #13
Re: c++
Gert Cuykens wrote:
No. FreeBSD is written in C. This is surely a mailing list for people> On Sun, 20 Feb 2005 12:47:50 +0000, Scott Mitchell
> <scott+lists.freebsd@fishballoon.org> wrote:
>>>>On Sun, Feb 20, 2005 at 08:41:30AM +0100, Gert Cuykens wrote:
>>>>>>>So if data is declared as a gchar *data; for example, then the value
>>>of data is a memory adress right ? So if A=data; and B=&data; then A
>>>and B are exactly the same result right ?
>>No. A is a 'pointer to gchar' (or gchar*) and B is a 'pointer to pointer
>>to gchar' (or gchar**). The '&data' syntax means 'the address of the data
>>variable', ie. the address of a gchar*, whereas data itself contains the
>>address of a gchar.
>>
>>>>>>>Now why would anybody want a gchar when a integer is needed ? That is
>>>just making it more complicated then it already is?
>>Because the code in question deals with gchars (whatever they are) not
>>integers? They won't necessarily be the same thing on different
>>architectures, or even different compilers on the same architecture. Also,
>>the type is called 'gchar' presumably because it logically holds some kind
>>of character data, whereas an integer variable holds an integer. Calling
>>them different things in the code helps to make it clear what the
>>programmer's intention is, even if the two types happen to have the same
>>representation on a given machine/compiler.
>>
>>In any case, this stuff really has nothing to do with FreeBSD - you should
>>be asking these questions in a C/C++ programming group.
>>
>>Cheers,
>>
>> Scott
>>
>>--
>
> Thx i think i understand now :)
>
> PS Freebsd source is c++ right ? So you could also call this the free
> c++ question mailing list :)
who want to ask and answer questions about the FreeBSD Operating System.
This is more like somebody passing your street asking for directions to>
> Also about all the get a c++ book comments, i tryed that once but when
> i ask the book a question, it doesnt say anything back. It only makes
> noises when you flaper the pages trough the wind.
>
> By the way if somebody passing your street asking for direction you
> dont answer get a map either right ?
>
a street in another country.
Both comp.lang.c and comp.lang.c++ are both pretty intolerant to people
asking basic questions which are heavily documented in the FAQs for the
newsgroups. They generally expect you to have at least tried to
understand what you are doing before asking a question. If you had
tried to understand your problem and looked at the faqs you would have
found an amazing amount of information on what you are after. Before
you do anything else you should now go read
[url]http://www.eskimo.com/~scs/C-faq/top.html[/url] and educate yourself a bit
more about C.
People are not trying to be unhelpful when the tell you to RTFM or read
a book. They are trying to point out areas of knowledge that you can
reference to gain more insight into your problem. Noone is just going
to do your homework for you.
Good luck learning about C.
Chris
Chris Hodgins Guest
-
Gert Cuykens #14
Re: c++
On Sun, 20 Feb 2005 10:58:54 -0500, David Vincelli <micologist@gmail.com> wrote:
lol no really, the B is a gchar** made sence.>> > Thx i think i understand now :)
> I wouldn't bet on it.
>
haha :)> Your analogy is invalid. Perhaps you can say that you walked into a
> fine cigar store and asked the seller about the territorial behaviour
> of south african howler monkeys. Would he give a crap about you?
> Maybe, but probably not. Learn some manners BY THE WAY.
Gert Cuykens Guest
-
Giorgos Keramidas #15
Re: c++
On 2005-02-20 16:34, Gert Cuykens <gert.cuykens@gmail.com> wrote:
Not quite, I'm afraid.>
> Thx i think i understand now :)
No. FreeBSD is written mostly in C. C++ is a very different language,> PS Freebsd source is c++ right ? So you could also call this the free
> c++ question mailing list :)
so please don't mix the two.
"Jokes" like this are not good responses to a list that you expect help> Also about all the get a c++ book comments, i tryed that once but when
> i ask the book a question, it doesnt say anything back. It only makes
> noises when you flaper the pages trough the wind.
from. We all know what books are good for. You do too.
That "direction" though may very well be a simple reference to a more> By the way if somebody passing your street asking for direction you
> dont answer get a map either right ?
authoritative source of information, i.e. a map. In the specific case
of programming languages, the standards or books that define the
languages are the _most_ authoritative sources of information.
Therefore, the reply "get yourself a good book and read it" is actually
correct.
Giorgos Keramidas Guest
-
Loren M. Lang #16
Re: c++
On Sun, Feb 20, 2005 at 04:38:32PM +0100, Gert Cuykens wrote:
That seems to be a good response based off of what your current level of> On Sun, 20 Feb 2005 16:15:43 +0100, Daniel S. Haischt
> <me@daniel.stefan.haischt.name> wrote:>> > Gert Cuykens,
> >
> > I would suggest to post such questions to [email]gtk-list@gnome.org[/email],
> > because IIRC you are trying to code a GTK app ...
> >
> > Additionally I would suggest to learn C/C++ first to get a better
> > understanding of the whole language structure. Or at least please
> > join the c# IRC channel at irc.freenode.net to ask such questions,
> > it's quite annoying to see them on a list which is dedicated to an
> > UNIX OS.
> I did that but they give me the get book and ask somebody els answer.
programmings skills seem to be. There are lots of good books on c/c++
that will be much more help to you than this list will be.
--> _______________________________________________
> [email]freebsd-questions@freebsd.org[/email] mailing list
> [url]http://lists.freebsd.org/mailman/listinfo/freebsd-questions[/url]
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"
I sense much NT in you.
NT leads to Bluescreen.
Bluescreen leads to downtime.
Downtime leads to suffering.
NT is the path to the darkside.
Powerful Unix is.
Public Key: [url]ftp://ftp.tallye.com/pub/lorenl_pubkey.asc[/url]
Fingerprint: B3B9 D669 69C9 09EC 1BCD 835A FAF3 7A46 E4A3 280C
Loren M. Lang Guest



Reply With Quote

