Connecting Tech Pros Worldwide Forums | Help | Site Map

Syntax Question

aurelien.chanudet@gmail.com
Guest
 
Posts: n/a
#1: Mar 16 '06
Hi all,

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

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

Thanks,
Aurelien


Richard Heathfield
Guest
 
Posts: n/a
#2: Mar 16 '06

re: Syntax Question


aurelien.chanudet@gmail.com said:
[color=blue]
> Hi all,
>
> Can someone tell me about the difference between these two statements ?
>
> char *string = _("foo");[/color]

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.
[color=blue]
> char *string = "foo";[/color]

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)
aurelien.chanudet@gmail.com
Guest
 
Posts: n/a
#3: Mar 16 '06

re: Syntax Question


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

Jaspreet
Guest
 
Posts: n/a
#4: Mar 16 '06

re: Syntax Question



aurelien.chanudet@gmail.com wrote:[color=blue]
> I didn't know "_" was legal as a function or macro name. Thanks ![/color]

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.

Jordan Abel
Guest
 
Posts: n/a
#5: Mar 16 '06

re: Syntax Question


On 2006-03-16, Jaspreet <jsingh.oberoi@gmail.com> wrote:[color=blue]
>
> aurelien.chanudet@gmail.com wrote:[color=green]
>> I didn't know "_" was legal as a function or macro name. Thanks ![/color]
>
> Identifiers beginning with _ (underscore) are valid in some
> implementations but may raise a error flag on other.[/color]

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)
[color=blue]
> 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.
>[/color]
Ben Pfaff
Guest
 
Posts: n/a
#6: Mar 16 '06

re: Syntax Question


Richard Heathfield <invalid@invalid.invalid> writes:
[color=blue]
> aurelien.chanudet@gmail.com said:
>[color=green]
>> Can someone tell me about the difference between these two statements ?
>>
>> char *string = _("foo");[/color]
>
> 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.[/color]

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
Martin Ambuhl
Guest
 
Posts: n/a
#7: Mar 16 '06

re: Syntax Question


aurelien.chanudet@gmail.com wrote:[color=blue]
> Hi all,
>
> Can someone tell me about the difference between these two statements ?
>
> char *string = _("foo");
> char *string = "foo";[/color]

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.
Closed Thread


Similar C / C++ bytes