'if' statement to control switch case

J

James Kanze

Fine. Look at it one year from now and figure out what it's supposed to
do. Especially if there's a bug related to it.

I'm with you on this one. Since the OP did mention "elegance",
comments about it are certainly on topic. But more generally,
if someone is adopting a bad approach, pointing this out to them
is generally more useful than finding a way to make the bad
approach work.

And of course, if the OP wants to be, and remain, gainfully
employed... Such code violates the coding guidelines of every
company I've worked in in the last 15 years or so, and people
who violate the coding guidelines aren't allowed to work on
code. (In the US, I imagine that they would be fired, but in
Europe, firing someone is a bit more difficult. On the other
hand, in general, "Ve haf vays to make you quit".)
Oh, and personal attacks like that really make me want to pay attention
to what you say.

Personal attacks are what one uses when one has no legitimate
arguments.
After 20 years of developing, debugging and
maintaining C and C++, I would loudly proclaim (and have done so -- in
the presence of said author) that the anyone who put code like that into
production should be shot.

I'm against capital punishment, but otherwise, I agree.
 
D

dave_mikesell

All I know is that if you worked for me, and you wrote code like that,
you'd get exactly one warning, and the next time you'd be fired.

All I know is that if I worked for a person who constantly held the
threat of firing over his employees' heads instead of teaching them
how to do things better, I'd quit.
 
J

James Kanze

We're probably OT from the OPs question,

Very. I've cross-posted to comp.std.c++, and set follow-ups
there, since that's really where the discussion belongs. (It's
something the standard should probably address, so that
implementors know what is required, but that no reasonable
programmer should be concerned with, since such cases won't
appear in his code.)
but I'm
unclear what you mean. Do you mean the words should have
used "otherwise" or something like that (myself, now that
I read the words, I'd have preferred "only" or something like
that too probably as well as otherwise).

To tell the truth, I'm not too sure myself. The problem is
trying to figure out what should happen, according to the
standard, if you enter the if statement by jumping over the
evaluation of the condition. The words I quoted could be taken
to suggest that on encountering the else, the condition must be
evaluated in order to determine whether the else part is to be
executed or not. (Note that I'm quite sure that this is not
the intent.) Something should be said to make it clear that 1)
the condition is only evaluated when the statement is entered
from the top, and 2) EITHER when the execution encounters the
else part (because it is executing in the if part), it skips it,
OR entering an if statement other than from the top is undefined
behavior.
 

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,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top