Ask a Question related to FreeBSD, Design and Development.

  1. #1

    Default c++

    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 * ?
    Gert Cuykens Guest

  2. #2

    Default Re: c++


    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

    Chad Leigh -- Shire.Net LLC Guest

  3. #3

    Default Re: 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 ?

    PS what is the difference between ?
    A=*data
    A=data
    A=&data
    Gert Cuykens Guest

  4. #4

    Default Re: c++

    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ł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 ?
    >
    >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"
    >
    >
    You should really get a book about programming or ask your teacher.
    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

  5. #5

    Default Re: c++


    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©©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 ?
    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

    Chad Leigh -- Shire.Net LLC Guest

  6. #6

    Default Re: c++

    Gert Cuykens writes:
    > What does coercing mean ?
    Telling the compiler to disregard mismatches between data types.
    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).
    > Why does the compiler have to match parameters ?
    To help avoid errors in coding, the compiler makes sure that the type of
    a variable matches what is expected in certain situations.
    > PS what is the difference between ?
    > 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


    Anthony Atkielski Guest

  7. #7

    Default Re: c++

    On Sun, 20 Feb 2005 00:17:31 +0100, Anthony Atkielski
    <atkielski.anthony@wanadoo.fr> wrote:
    > > 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
    >
    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 ?

    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

  8. #8

    Default Re: c++

    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

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

  9. #9

    Default Re: c++

    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 :)

    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

  10. #10

    Default Re: c++

    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.
    Gert Cuykens Guest

  11. #11

    Default Re: c++

    On Sun, Feb 20, 2005 at 04:34:45PM +0100, Gert Cuykens wrote:
    >
    > Thx i think i understand now :)
    >
    > PS Freebsd source is c++ right ? So you could also call this the free
    > c++ question mailing list :)
    FreeBSD is almost entirely written in C, although there are a few bits of
    C++ under /usr/src.

    This is a list for questions about FreeBSD, not basic C++ programming.
    > 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.
    Get a better book? Sign up for a C/C++ course?
    > By the way if somebody passing your street asking for direction you
    > dont answer get a map either right ?
    No, but you didn't ask me, you asked maybe 10,000 people you've never met,
    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

  12. #12

    Default Re: c++

    Gert Cuykens <gert.cuykens@gmail.com> wrote:
    > PS Freebsd source is c++ right ? So you could also call this the free
    > c++ question mailing list :)
    No and no.
    > 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.
    That's very funny. Perhaps you should be a comedian instead of a
    programmer.
    > By the way if somebody passing your street asking for direction you
    > dont answer get a map either right ?
    Those responses are NOT rude, as you seem to imply. The simple fact
    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

  13. #13

    Default Re: c++

    Gert Cuykens wrote:
    > 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 :)
    No. FreeBSD is written in C. This is surely a mailing list for people
    who want to ask and answer questions about the FreeBSD Operating System.
    >
    > 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 ?
    >
    This is more like somebody passing your street asking for directions to
    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

  14. #14

    Default Re: c++

    On Sun, 20 Feb 2005 10:58:54 -0500, David Vincelli <micologist@gmail.com> wrote:
    > > Thx i think i understand now :)
    >
    > I wouldn't bet on it.
    >
    lol no really, the B is a gchar** made sence.
    > 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.
    haha :)
    Gert Cuykens Guest

  15. #15

    Default Re: c++

    On 2005-02-20 16:34, Gert Cuykens <gert.cuykens@gmail.com> wrote:
    >
    > Thx i think i understand now :)
    Not quite, I'm afraid.
    > PS Freebsd source is c++ right ? So you could also call this the free
    > c++ question mailing list :)
    No. FreeBSD is written mostly in C. C++ is a very different language,
    so please don't mix the two.
    > 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.
    "Jokes" like this are not good responses to a list that you expect help
    from. We all know what books are good for. You do too.
    > By the way if somebody passing your street asking for direction you
    > dont answer get a map either right ?
    That "direction" though may very well be a simple reference to a more
    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

  16. #16

    Default Re: c++

    On Sun, Feb 20, 2005 at 04:38:32PM +0100, Gert Cuykens wrote:
    > 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.
    That seems to be a good response based off of what your current level of
    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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139