What is the purpose of the underscore before parenthesis?

M

Mark Hobley

I am looking at a line of C code, as follows:

printf (_("Usage: %s [OPTION]...\n"), program_name);

^
|
What is the purpose of this underscore character?

Mark.
 
K

Kojak

Le Thu, 26 Feb 2009 09:08:02 GMT,
Mark Hobley a écrit :
printf (_("Usage: %s [OPTION]...\n"), program_name);

^
|
What is the purpose of this underscore character?

A macro defined somewhere... Probably a gettext macro for l10n.
 
T

TonyMc

I am looking at a line of C code, as follows:

printf (_("Usage: %s [OPTION]...\n"), program_name);

^
|
What is the purpose of this underscore character?

Mark.

I think it is a macro defined in <windows.h> whose expansion depends on
whether or not the UNICODE macro is defined. The effect is to prefix an
L to the string (make the characters wchar_t) if you need UNICODE.

Tony
 
K

Kaz Kylheku

I am looking at a line of C code, as follows:

printf (_("Usage: %s [OPTION]...\n"), program_name);

^
|
What is the purpose of this underscore character?

It is an identifier.

This is a primary expression denoting a function or object:

_

This is a postfix expression denoting a function call of one argument:

_("string literal")

Of course it could be a function-like preprocessor macro.

Some GNU programs use such a fucntion or macro convention for denoting
internationalizable strings within program source. The underscore generates
code which will fetch the translation of the string into different languages.

The underscore is used probably because it is visually unobtrusive, compared to
, say, printf(gettext("Usage: %s ..."), ).
 
G

gw7rib

[email protected] (Mark Hobley) said:
I am looking at a line of C code, as follows:
 printf (_("Usage: %s [OPTION]...\n"), program_name);
         ^
         |
         What is the purpose of this underscore character?

I think it is a macro defined in <windows.h> whose expansion depends on
whether or not the UNICODE macro is defined. The effect is to prefix an
L to the string (make the characters wchar_t) if you need UNICODE.

I don't think so. There is a macro called _TEXT which does as you say,
and I think _T will also do that. But I don't think there is a macro
called just _ which will do that. I think the correct answer, as other
people in the thread have said, is internationalisation (or
localisation, depending which way you look at it) - it will either
leave the string alone or it will convert it to another string saying
the same thing in a different language.
 
C

CBFalconer

TonyMc said:
I am looking at a line of C code, as follows:

printf (_("Usage: %s [OPTION]...\n"), program_name);
^
|
What is the purpose of this underscore character?

I think it is a macro defined in <windows.h> whose expansion
depends on whether or not the UNICODE macro is defined. The
effect is to prefix an L to the string (make the characters
wchar_t) if you need UNICODE.

Why are you guessing? Look up where it is defined. It is most
likely a function which allows replacement of its operand, used to
change languages.
 
R

Richard

CBFalconer said:
TonyMc said:
I am looking at a line of C code, as follows:

printf (_("Usage: %s [OPTION]...\n"), program_name);
^
|
What is the purpose of this underscore character?

I think it is a macro defined in <windows.h> whose expansion
depends on whether or not the UNICODE macro is defined. The
effect is to prefix an L to the string (make the characters
wchar_t) if you need UNICODE.

Why are you guessing? Look up where it is defined. It is most
likely a function which allows replacement of its operand, used to
change languages.

And yet you go on to guess. You truly are a legend in your own lunchtime
Chuck.
 
T

TonyMc

CBFalconer said:
Why are you guessing? Look up where it is defined. It is most
likely a function which allows replacement of its operand, used to
change languages.

You are right to say that I should have looked up the definition. You
are wrong to say that my answer was guesswork, it was simply a mistake.
I was fairly confident about my recollection but it turns out I was
thinking of the _T() macro, as another poster has pointed out. It
wasn't easy for me to check because I wasn't on a windows machine at the
time and so didn't have the relevant headers available to look through.

When I read comp.lang.c it is only rarely that I think it is worth
contributing to the discussion. That is usually because, by the time I
read a question that I can answer with some confidence, several other
posters have already given their answers. If their answers were
correct, I have nothing to add, if not, usually lots of others have
already pointed out the mistake. On this occasion, I read Mark's
question, saw no replies and thought "Hey, here's one I can answer!" -
which turned out to be a bit hasty. I apologise for adding to the noise
in this group, and especially to Mark for giving a misleading answer.
Back to lurking in the group's shadows.

Best,
Tony
 
J

Joachim Schmitz

blargg said:
Joachim said:
Le Thu, 26 Feb 2009 09:08:02 GMT,
Mark Hobley a écrit :

printf (_("Usage: %s [OPTION]...\n"), program_name);

^

What is the purpose of this underscore character?

A macro defined somewhere...

or a function


Probably a gettext macro for l10n.

I18N? (Internationalisation)

l10n, Localisation

Good thing we've saved all that bandwidth by using these cryptic
abbreviations, and follow-ups to clarify what they mean.

I18N and L10N are widely used acronyms. I don't particularly like them
though, and find it quite strange to abbreviate them, in German we have much
longer words :cool:

Bye, Jojo
 
S

Stephen Sprunk

Joachim said:
I18N and L10N are widely used acronyms. I don't particularly like them
though, and find it quite strange to abbreviate them, in German we have
much longer words :cool:

English is, to a large degree, defined by the laziness of its speakers;
when a long word or phrase comes into common use, it is almost always
abbreviated (or a shorter, unrelated word is substituted) to appease our
laziness. Think of it as arithmetic compression applied to linguistics:
the more important the word, the shorter it becomes, just like Huffman
encoding will assign shorter bit strings to more common letters. One
result is that English text is usually shorter than translations into
other alphabetic languages...

I18N and L10N are in limbo: long enough to annoy the people that use
them frequently in one niche, but not used enough by the general
population for newer, shorter words to evolve and be accepted. Every
field has such terms...

S
 
G

Guest

blargg said:
Joachim said:
(e-mail address removed) wrote:
Le Thu, 26 Feb 2009 09:08:02 GMT,
Mark Hobley a écrit :
printf (_("Usage: %s [OPTION]...\n"), program_name);
^
What is the purpose of this underscore character?
A macro defined somewhere...
or a function
Probably a gettext macro for l10n.
I18N? (Internationalisation)
l10n, Localisation
Good thing we've saved all that bandwidth by using these cryptic
abbreviations, and follow-ups to clarify what they mean.

I18N and L10N are widely used acronyms. I don't particularly like them
though, and find it quite strange to abbreviate them, in German we have much
longer words  :cool:

those are what other languages call "sentences"

:)
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top