problems/risks due to programming language
Peter da Silva
peter at ficc.uu.net
Sat Feb 24 04:25:15 AEST 1990
With apologies to all the people tired of Bill Wolfe's Adaphilic C-bashing,
the people arguing that you *need* break are all wet. Observe:
switch(c)
{
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
digit();
default:
not_a_digit();
}
On the other hand, the people (inlcuding Bill) arguing that switch...break
is an unalloyed disaster are also all wet. The C SWITCH is not a Pascal
CASE, it's a computed goto:
switch(c)
{
case '%':
stuff...
break;
case '$':
stuff...
break;
case '\\':
nextc = getchar();
if(nextc == '%' || nextc == '$')
c = nextc;
else
ungetc(nextc, stdin);
/* FALLTHROUGH */
default:
lots...
of...
stuff...
break;
}
The right solution for Next C (whether it be P or D) is to defang break
by using a different keyword for breaking from a switch or exiting from
a loop. I would suggest that 'break' be given a mandatory keyword argument:
either 'break switch', 'break for', and so on.
--
_--_|\ Peter da Silva. +1 713 274 5180. <peter at ficc.uu.net>.
/ \
\_.--._/ Xenix Support -- it's not just a job, it's an adventure!
v "Have you hugged your wolf today?" `-_-'
More information about the Comp.lang.c
mailing list