LinuxSA Mailing list archives

Index: [thread] [date] [subject] [author] [stats]
  From: <davidn@rebel.net.au>
  To  : Jake Hawkes <jakehawkes2001@yahoo.com>
  Date: Fri, 30 Nov 2001 10:40:58 +1030 (CST)

Re: strange C code

Jake Hawkes <jakehawkes2001@yahoo.com> wrote:
> Thing is, it does look ahead to the tightest match

No, it branches to the *exact* match; absenting that, to the default,
if any.


> If it was a truely interperated thing, it would match all the mathces
> in order of apearance (like sh and perl).

No, if it was an interpreted implementation (and there is at least one
interpreted C) it would do whatever the language is designed to do.
There's nothing difficult about interpreting C's switch statement.
If you think that sh's case statement is analagous, and that it has a
default you are wrong.  It has a list of regular expressions, and the
regex "*" does NOT mean default, it mean specifically match anything.
The distinction is only subtle if you think carelessly.


> I mean I say "should be" only because it cost some time to find the bug.

Still no, it took some time for you to understand the language.


> consider triply nested switch statements, and some jerk put a default
> case at the top of one of the inner switches.

You could easily think the default belonged to one of the other switch
statements, but then you could equally think that all of its cases also
belonged to the other switch.

-- 
LinuxSA WWW: http://www.linuxsa.org.au/  IRC: #linuxsa on irc.linux.org.au
To unsubscribe from the LinuxSA list:
  mail linuxsa-request@linuxsa.org.au with "unsubscribe" as the subject


Index: [thread] [date] [subject] [author] [stats]
Return to the LinuxSA Mailing List Information Page