Syntax Question

Discussion in 'C Programming' started by aurelien.chanudet@gmail.com, Mar 16, 2006.

  1. Guest

    Hi all,

    Can someone tell me about the difference between these two statements ?

    char *string = _("foo");
    char *string = "foo";

    Thanks,
    Aurelien
    , Mar 16, 2006
    #1
    1. Advertising

  2. said:

    > Hi all,
    >
    > Can someone tell me about the difference between these two statements ?
    >
    > char *string = _("foo");


    This is a function call to a function named _ which appears to accept a
    const char * (or, lamely, a char *) and return a pointer to char. What
    value it returns is anyone's guess. Alternatively, _ might be a macro.

    > char *string = "foo";


    This is a definition and initialisation of a pointer to char. Its initial
    value is the address of the first character in the string literal, "foo". A
    better definition would be:

    const char *string = "foo";

    as you wouldn't want accidentally to modify the contents of a string literal
    through a pointer, now would you?

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
    Richard Heathfield, Mar 16, 2006
    #2
    1. Advertising

  3. Guest

    I didn't know "_" was legal as a function or macro name. Thanks !
    , Mar 16, 2006
    #3
  4. Jaspreet Guest

    wrote:
    > I didn't know "_" was legal as a function or macro name. Thanks !


    Identifiers beginning with _ (underscore) are valid in some
    implementations but may raise a error flag on other. So to make your
    program a portable solution, its ideal to not have an identifier name
    starting with _.

    But then we do not live in an ideal world.
    Jaspreet, Mar 16, 2006
    #4
  5. Jordan Abel Guest

    On 2006-03-16, Jaspreet <> wrote:
    >
    > wrote:
    >> I didn't know "_" was legal as a function or macro name. Thanks !

    >
    > Identifiers beginning with _ (underscore) are valid in some
    > implementations but may raise a error flag on other.


    Not quite. they're 'reserved', so using them causes undefined behavior.
    There is also a distinction between A) identifiers beginning with an
    underscore and an uppercase letter (these are reserved everywhere) and
    B) identifiers beginning with an underscore and a lowercase letter, an
    underscore and a digit, or the identifier consisting of an underscore
    alone (these are only reserved in some contexts, and not others)

    > So to make your
    > program a portable solution, its ideal to not have an identifier name
    > starting with _.
    >
    > But then we do not live in an ideal world.
    >
    Jordan Abel, Mar 16, 2006
    #5
  6. Ben Pfaff Guest

    Richard Heathfield <> writes:

    > said:
    >
    >> Can someone tell me about the difference between these two statements ?
    >>
    >> char *string = _("foo");

    >
    > This is a function call to a function named _ which appears to accept a
    > const char * (or, lamely, a char *) and return a pointer to char. What
    > value it returns is anyone's guess. Alternatively, _ might be a macro.


    My guess is that _ is a macro that expands to gettext, because
    that's a common convention in Unix code. In turn,
    gettext("Hello!") might return "Bonjour!"; in other words, it's
    used for internationalization.
    --
    "I hope, some day, to learn to read.
    It seems to be even harder than writing."
    --Richard Heathfield
    Ben Pfaff, Mar 16, 2006
    #6
  7. wrote:
    > Hi all,
    >
    > Can someone tell me about the difference between these two statements ?
    >
    > char *string = _("foo");
    > char *string = "foo";


    The first has no meaning without more context. Most likely, _() is a
    macro the definition of which you have decided not to show us, for your
    own secret reasons.
    Martin Ambuhl, Mar 16, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gabriele renzi
    Replies:
    2
    Views:
    193
    gabriele renzi
    Dec 31, 2005
  2. Ken Bloom
    Replies:
    3
    Views:
    193
  3. Good Night Moon
    Replies:
    9
    Views:
    267
    Rick DeNatale
    Jul 25, 2007
  4. Jacob Grover
    Replies:
    5
    Views:
    304
    Jacob Grover
    Jul 18, 2008
  5. Mark Richards
    Replies:
    3
    Views:
    303
    Tad McClellan
    Nov 18, 2007
Loading...

Share This Page