Syntax Question

A

aurelien.chanudet

Hi all,

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

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

Thanks,
Aurelien
 
R

Richard Heathfield

(e-mail address removed) 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?
 
J

Jaspreet

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.
 
J

Jordan Abel

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

Ben Pfaff

Richard Heathfield said:
(e-mail address removed) said:


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.
 
M

Martin Ambuhl

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top