Are C pitfalls the mistake of standard or that of implementations ?

  • Thread starter Jonathan Bartlett
  • Start date
E

Espen Myrland

Joona I Palaste said:
Espen Myrland


This would have been funnier if *cough* was proper syntax for a C type.


Yess. I know. I first removed it and then put it back.


regards,
 
B

Bart C

Correct, there are no errors in that statement. The error is in your
compiler, and the code snippet is one way to fix it (altering the
variables to suit).

Hint: is one plural?

Took me a while to get your point. However I think that is a little unfair.
I'm using an MS OS which (with their thousands of staff and tens of billions
of pounds) is still sprinkled with "1 Files", "1 Folders" and so on. Maybe
the idea of having just ONE file might be alien to them.

My own efforts are better behaved but sometimes dealing with multi-languages
means plurals are not that straightforward. But no excuse for MS though.

Bart
 
C

Chris Croughton

Chris: Jacob's (*cough*) reply hasn't hit my server yet, so thanks
for setting him straight.

De nada. The message "1 errors" and friends is one of my bugbears, it
indicates to me that the code is not production quality (it's those
little touches which make the difference in Real World(tm) programs
between being bought and being ignored).
Sometimes I despair of humanity, I really do.

Only sometimes? Well, you're young, you have lots of despair ahead of
you <g>...

Chris C
 
J

jacob navia

Bart said:
Took me a while to get your point. However I think that is a little unfair.
I'm using an MS OS which (with their thousands of staff and tens of billions
of pounds) is still sprinkled with "1 Files", "1 Folders" and so on. Maybe
the idea of having just ONE file might be alien to them.

My own efforts are better behaved but sometimes dealing with multi-languages
means plurals are not that straightforward. But no excuse for MS though.

Bart


Me too <grin> it took me a while to get your point...
I thought at first sight that you were saying that when
a complex expression appeared as an argument of printf
the compiler would fail...

Well, yesssssss, the customer is always right but now my compiler
says:

0 error, 1 warning

It should be

0 errors, 1 warning isn't it?

Or should I drop the message if there is only one
error? Actually it doesn't make sense to summarize
the error/warning count when there is only one isn't it?

Etc, etc...
 
C

Chris Croughton

Took me a while to get your point. However I think that is a little unfair.
I'm using an MS OS which (with their thousands of staff and tens of billions
of pounds) is still sprinkled with "1 Files", "1 Folders" and so on.

I rest my case said:
Maybe
the idea of having just ONE file might be alien to them.

They've done it since early PCDOS times, when often there was only one
file on the floppy...
My own efforts are better behaved but sometimes dealing with multi-languages
means plurals are not that straightforward. But no excuse for MS though.

Yes, i18n is more of a problem. The solution is similar, though, you
just need to put the whole words in the conditionals:

printf("%d %s\n", number,
number == 1 ? gettext("file") : gettext("files"));

(or something like that).

Chris C
 
C

Chris Croughton

Well, yesssssss, the customer is always right but now my compiler
says:

0 error, 1 warning

It should be

0 errors, 1 warning isn't it?

Correct. In most western European languages at least the only singular
number is one, zero is regarded as gramatically plural (I don't know
much about middle- and far-eastern languages, nor about those native to
the American and Pacific areas).

<OT>
Most W.E. languages except English have a construct which translates as
"isn't it?" which is often appended to sentences: "n'est pas", "nicht
wahr", etc. English seems to have largely dropped that construct...
Or should I drop the message if there is only one
error? Actually it doesn't make sense to summarize
the error/warning count when there is only one isn't it?

I don't mind seeing something like:

0 errors, 0 warnings

but Unix-like utilities have traditionally not displayed anything at all
for 'success', only for failure (except of course for utilities the
purpose of which is to produce output to the user).

Chris C
 
C

Christian Bau

Chris Croughton said:
They've done it since early PCDOS times, when often there was only one
file on the floppy...


Yes, i18n is more of a problem. The solution is similar, though, you
just need to put the whole words in the conditionals:

printf("%d %s\n", number,
number == 1 ? gettext("file") : gettext("files"));

(or something like that).

This depends very much on the language you are using. English is
relatively simple. Different languages treat the number zero
differently; in some languages it would be "0 file", in others it would
be "0 files". Some languages have different words for 0, 1, and many. In
some languages it depends on the last digit: It would be "101 file", but
"102 files". And there are probably rules when to use words instead of
digits ("one file", not "1 file").

Now to make things a bit more complicate, try to write code that prints
"1st file", "2nd file" and so on correctly for arbitrary numbers. Then
try to investigate the rules for different languages. Have fun.
 
E

Eric Sosman

Chris said:
[...]
Yes, i18n is more of a problem. The solution is similar, though, you
just need to put the whole words in the conditionals:

printf("%d %s\n", number,
number == 1 ? gettext("file") : gettext("files"));

Long ago my Latin teacher grew impatient with our
constant grumbling at trying to memorize the ten forms
of every noun, thirty forms of every adjective, and 120-odd
forms of every verb. We didn't know how lucky we were,
said he, because if we'd been studying Greek the job would
have been roughly fifty percent harder. Whenever a Latin
word had singular and plural forms, Greek had singular and
dual (exactly two) and plural (three or more) forms ...

Q1: Can any Greek speakers vouch for my old Latin
teacher's assertion? (He may have been kidding us.)

Q2: If I mistake not, gettext() would have a hard
time with this situation because the mapping of distinct
dual and plural Greek words to a single English plural
would be non-invertible.
 
J

jacob navia

Chris said:
but Unix-like utilities have traditionally not displayed anything at all
for 'success', only for failure (except of course for utilities the
purpose of which is to produce output to the user).

lcc-win32 doesn't print anything if there are no errors
and no warnings. The objective is when you have a lot of
warnings but no errors to avoid having to look up all the
output to see if there is an error...

OK now it is:
if (errcnt > 0 || warningCount > 0) {
printf("%d error%s, %d warning%s", errcnt,
(errcnt != 1) ? "s" : "",
warningCount, warningCount != 1 ? "s":"");
}

Small improvement but wothwhile.

Thanks for the tip :)
 
I

infobahn

[...] it took me a while to get your point...

Review the thread to find out who actually made the point.

Well, yesssssss, the customer is always right but now my compiler
says:

0 error, 1 warning

Then you didn't implement correctly the code I showed you. (Note
that I am neither Chris nor Bart.)

Did you really really really write a compiler? Furrfu.
 
C

Chris Barts

Chris said:
The message "1 errors" and friends is one of my bugbears, it indicates
to me that the code is not production quality (it's those
little touches which make the difference in Real World(tm) programs
between being bought and being ignored).

It might mean that the author needs to translate the error messages
automatically with something like gettext (more precisely, switch
automatically between multiple human-written translations) and can't
sensibly do plurals without wasting too much of his time on what is, in
the end, a very minor issue.

In other words, people who make judgments like that without context get
bitten by their own smugness.
 
A

Arthur J. O'Dwyer

It might mean that the author needs to translate the error messages
automatically with something like gettext (more precisely, switch
automatically between multiple human-written translations) and can't sensibly
do plurals without wasting too much of his time on what is, in the end, a
very minor issue.

No, I don't see that. I don't agree that such a minor defect would make
the difference between "being bought and being ignored," but neither would
I consider a program that printed "1 errors" really production-quality.
(Conclusion: I think a lot of people buy software that is not
production-quality.)
Sure, it might be a defect whose root cause was the laziness of the
gettext programmer or user, rather than the laziness of a hand-coding
programmer, but it's still a glaringly obvious defect that shouldn't
have slipped through testing.
If the project absolutely must use some gettext-like system that doesn't
support English plurals, then the obvious solution (to me) would be

Errors: 0
Warnings: 1

-Arthur
 
M

Michael Wojcik

Correct. In most western European languages at least the only singular
number is one, zero is regarded as gramatically plural (I don't know
much about middle- and far-eastern languages, nor about those native to
the American and Pacific areas).

Some of those don't even have gramatical number. Likely there are
many variations, which is an argument for not trying to handle
grammatical number in messages. Even dealing only with languages
that follow the English pattern (one inflection for singular, used
only with 1; another for plural, used with all other values) you
have to store two message templates for each language - the singular
and the plural version. More if there are multiple values (as there
are here). You can't cover all the languages with a rule like
"pass either "s" or "" for parameter N depending on the value of
parameter N-1"; there's no guarantee that will form the correct
plural in every language.

I think the best option is to avoid grammatical number entirely,
by not making the numeric value part of the phrase proper:

Number of errors: 0. Number of warnings: 1.
<OT>
Most W.E. languages except English have a construct which translates as
"isn't it?" which is often appended to sentences: "n'est pas", "nicht
wahr", etc. English seems to have largely dropped that construct...
</OT>

Depends on dialect, no? I frequently see, and occasionally employ, a
simple "no?" in this manner. "doesn't it?" and "isn't it?" are
common in at least some parts of the US (I've heard them from
speakers from the coasts, for example). In some Carribean dialects
"seen?" is used this way. There are other forms in other dialects.

In the spirit of posting meaningless statistics to Usenet, I note that
a quick Google search showed 57 uses of the appended "doesn't it?" in
the past 24 hours' Usenet posts.

Of course it's quite possible that such usage is rare in the dialects
you most frequently encounter.
 
C

Chris Croughton

lcc-win32 doesn't print anything if there are no errors
and no warnings. The objective is when you have a lot of
warnings but no errors to avoid having to look up all the
output to see if there is an error...

Of course, if there was an error you still have to locate it amongst all
of the warnings...

There is a philosophical split between Unix types, who like to have no
output at all for success, and those used to Certain Other Systems who
like explicit confirmation of success ("Look, you got it right!").
OK now it is:
if (errcnt > 0 || warningCount > 0) {
printf("%d error%s, %d warning%s", errcnt,
(errcnt != 1) ? "s" : "",
warningCount, warningCount != 1 ? "s":"");
}

Small improvement but wothwhile.

Yup. As I said, it's something which indicates to many people
(including me) that the implementor has actually thought about it rather
than just shoving anything in. I feel the same about estimated time
displays which are broken (MS are prime culprits there as well), it's not
difficult to get right...
Thanks for the tip :)

No problem. Anything which makes me less unhappy <g>...

Chris C
 
M

Michael Wojcik

Long ago my Latin teacher grew impatient with our
constant grumbling at trying to memorize the ten forms
of every noun, thirty forms of every adjective, and 120-odd
forms of every verb. We didn't know how lucky we were,
said he, because if we'd been studying Greek the job would
have been roughly fifty percent harder. Whenever a Latin
word had singular and plural forms, Greek had singular and
dual (exactly two) and plural (three or more) forms ...

Q1: Can any Greek speakers vouch for my old Latin
teacher's assertion? (He may have been kidding us.)

According to my handy Greek textbook, the dual form is "obsolescent
in classical Greek, though frequent in Homer". I'm not sure what
exactly they mean by "classical Greek" here.

The text also notes that in Attic Greek the dual is sometimes used
for "natural pairs" (a pair of hands and such) but "other words in
agreement with [a noun in the dual] are sometimes found in the
plural".
Q2: If I mistake not, gettext() would have a hard
time with this situation because the mapping of distinct
dual and plural Greek words to a single English plural
would be non-invertible.

Yes, clearly there can't be a one-to-one mapping from two numbers
to three. :)

I can see ancient Greek would be a bit of trouble. For nouns and
adjectives you have two or three numbers (singular, plural, maybe
dual); three genders (masculine, feminine, neuter); and five cases
(nominative, genitive, dative, accusative, vocative). There are
three declensions (forms of the combinations of the above), plus
some irregulars. For adverbs and pronouns you have five cases, but
they're different from those for nouns (interrogative, indefinite,
demonstrative, relative, and indefinite relative / indirect
interrogative).

And verbs are tough. The book gives the "complete paradigm" for
one omega-verb (one of the standard verb forms): it goes on for
five pages, showing several hundred forms. (And why not? You
wouldn't want to use just anything for a passive first aorist
optative second-person plural. Someone might get confused.)

--
Michael Wojcik (e-mail address removed)

Company Secretary Finance Manager
1) Half-grey haired executives.
2) Must be waist-deep in their field of activities.
3) Must be having the know-how and the do-how of the latest
developments in their respective fields.
-- from "Appointments Vacant" section of Business India
 
C

CBFalconer

jacob said:
lcc-win32 doesn't print anything if there are no errors
and no warnings. The objective is when you have a lot of
warnings but no errors to avoid having to look up all the
output to see if there is an error...

OK now it is:
if (errcnt > 0 || warningCount > 0) {
printf("%d error%s, %d warning%s", errcnt,
(errcnt != 1) ? "s" : "",
warningCount, warningCount != 1 ? "s":"");
}

I would avoid all that foofaraw with:

if (errcnt || warningCount)
printf("Errors : %d, Warnings : %d\n" errcnt, warningCount);

EOGH (end of grammar hassles)
 
R

Richard Bos

It's worse. There are at least six past tenses, and you're expected to
know them all. When I heard about that, I dropped it like a hot potato,
and kept Latin.
According to my handy Greek textbook, the dual form is "obsolescent
in classical Greek, though frequent in Homer". I'm not sure what
exactly they mean by "classical Greek" here.

I presume Greek as spoken in the classical period; that is, roughly
around the Persian and Pelepponesian wars. Most of the great classic
authors wrote during that period, beginning with Aischylos and ending
with Xenophon. Homer was a couple of centuries earlier, and was
considered historical and old-fashioned (but highly important) already.

Richard
 
K

Keith Thompson

CBFalconer said:
jacob navia wrote: [...]
OK now it is:
if (errcnt > 0 || warningCount > 0) {
printf("%d error%s, %d warning%s", errcnt,
(errcnt != 1) ? "s" : "",
warningCount, warningCount != 1 ? "s":"");
}

I would avoid all that foofaraw with:

if (errcnt || warningCount)
printf("Errors : %d, Warnings : %d\n" errcnt, warningCount);

EOGH (end of grammar hassles)

If you don't have to worry about internationalization, the
(errcnt != 1) ? "s" : ""
approach makes sense -- but it's likely that you will have to worry
about it some day.

It might make sense for an internationalization package to provide
a function like
char *plural(char *word, int count);
plural("Error", 2) would return "Errors" for English, something using
the grammatical dual number for pre-classical Greek, and do forth.
(Managing storage for the returned string is left as an exercise.)

This doesn't help much if you want to write "There was 1 error"
vs. "There were 2 errors".

Probably the folks in comp.software.international (which I've never
read) would have a lot more to say about this.
 

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,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top