Re: switch() Statement Question
- From: Eric Sosman <Eric.Sosman@xxxxxxx>
- Date: Tue, 31 Mar 2009 12:02:43 -0400
Rob Clarke wrote:
Ben Bacarisse scribbled:Han from China is messing you (and everyone else) about. Review is
posting history and decided how long you want to spend debating this
point.
Ah, I should have caught that. I am curious now, though: How many `case' labels can a strictly conforming program get away with using? If it's not the patently
absurd 0, as Han from China seems to be suggesting, what does the standard actually guarantee?
C90 guarantees 257 case labels, C99 guarantees 1023. As I read
it, these do not include a possible default: label.
The "guarantees," however, are a little weaker than might be
supposed. Here's the relevant C99 text (5.2.4.1p1):
The implementation shall be able to translate and execute
at least one program that contains at least one instance
of every one of the following limits:
.... which is the Standard's acknowledgment that different features
of a program may put stress on the same parts of an implementation.
For example, there's a C99 "guarantee" of at least 127 levels of
nested blocks, but it does not follow that you can successfully
compile a program where a function's body (outermost block) contains
a switch with 1024 branches (1023 cases plus default), each branch
containing another similar switch, and so on down through 126 levels
of switch for 1024 + 1024^2 + ... + 1024^126 = (1024^127 - 1) / 1023
or approximately 2E379 branches in all! (One immediate difficulty
is that there's not enough disk space on Planet Earth to hold the
source code ...)
Some people (and I see by the quoted material that you've run
into one of them) have used this "one program, one instance" text
to support a specious argument that there are no useful guarantees.
The idea is that an implementation could fulfill the guarantees by
exhibiting a fixed set of programs that collectively exercised all
the limits, and then rejecting all other source codes as "too big."
Okay, fine, they've had their fun. One only wishes that they wouldn't
keep cackling over the same tired old joke.
--
Eric.Sosman@xxxxxxx
.
- Follow-Ups:
- Re: switch() Statement Question
- From: Han from China
- Re: switch() Statement Question
- From: jameskuyper
- Re: switch() Statement Question
- References:
- Re: switch() Statement Question
- From: Rob Clarke
- Re: switch() Statement Question
- From: Han from China
- Re: switch() Statement Question
- From: Rob Clarke
- Re: switch() Statement Question
- From: Ben Bacarisse
- Re: switch() Statement Question
- From: Rob Clarke
- Re: switch() Statement Question
- Prev by Date: Re: Explanation of ? operator missing in reference guide
- Next by Date: C scripting (continued)
- Previous by thread: Re: switch() Statement Question
- Next by thread: Re: switch() Statement Question
- Index(es):
Relevant Pages
|