help me atleast now

K

Keith Thompson

santosh said:
Default said:
Kenneth said:
santosh wrote:
Though Turbo C++ 3.0, which the OP uses, is not given, it's 1.0
version is provided and it exhibits the same bug. The C compiler
however is correct. I wonder for how many more rarely used
constructs like these, they trip up on? Maybe, they didn't do all
the rigorous software testing that's done these days.

Does the bug only occur with "for(;0;)"? What about:

for ( ; a>b ; )
printf("Yup, the bug is still here.\n");
return(0);
}

That's a good question. What about something like:

char s[] = "";

for(;*s;)
printf("Yup, the bug is still here.\n");

The "bug" doesn't appear, both for global and local s.
That seems common enough that it should have turned up in common usage.

The bug seems to be produced only with a numeric literal. There may be
other possibilities too, but whose's going to bother testing
exhaustively such an outdated compiler/s.

I'll bet it's an optimization gone awry. The author(s) probably tried
to optimize the case of a constant condition and got the logic
backwards.

I wonder whether "for (;1;)" also misbehaves.
 
S

santosh

Keith said:
santosh said:
Default said:
Kenneth Brody wrote:
santosh wrote:
Though Turbo C++ 3.0, which the OP uses, is not given, it's 1.0
version is provided and it exhibits the same bug. The C compiler
however is correct. I wonder for how many more rarely used
constructs like these, they trip up on? Maybe, they didn't do all
the rigorous software testing that's done these days.

Does the bug only occur with "for(;0;)"? What about:


for ( ; a>b ; )
printf("Yup, the bug is still here.\n");
return(0);
}

That's a good question. What about something like:

char s[] = "";

for(;*s;)
printf("Yup, the bug is still here.\n");

The "bug" doesn't appear, both for global and local s.
That seems common enough that it should have turned up in common usage.

The bug seems to be produced only with a numeric literal. There may be
other possibilities too, but whose's going to bother testing
exhaustively such an outdated compiler/s.

I'll bet it's an optimization gone awry. The author(s) probably tried
to optimize the case of a constant condition and got the logic
backwards.

I wonder whether "for (;1;)" also misbehaves.

Nope. It results in an infinite loop as it should. Thus far it only
seems to occur for literal constant 0. I'm rather surprised though that
nobody seems to have spotted it in about 15 years.
 
K

Keith Thompson

santosh said:
Nope. It results in an infinite loop as it should. Thus far it only
seems to occur for literal constant 0. I'm rather surprised though that
nobody seems to have spotted it in about 15 years.

Are you sure nobody has ever spotted it? It appears to have been
fixed in later releases, so either somebody noticed it or it vanished
in a code rewrite.
 
K

Kenneth Brody

santosh wrote:
[...]
Does the bug only occur with "for(;0;)"? What about: [...]
The bug seems to be produced only with a numeric literal. There may be
other possibilities too, but whose's going to bother testing
exhaustively such an outdated compiler/s.

I'll bet it's an optimization gone awry. The author(s) probably tried
to optimize the case of a constant condition and got the logic
backwards.

I wonder whether "for (;1;)" also misbehaves.

Nope. It results in an infinite loop as it should. Thus far it only
seems to occur for literal constant 0. I'm rather surprised though that
nobody seems to have spotted it in about 15 years.

Well, the bug was fixed in a later release, either intentionally (because
someone found it) or unintentionally (in which case it was no longer there
to be "spotted").

In either case, how often does one write "for(;0;)"? (BTW, does "while(0)"
fail the same way?)

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:[email protected]>
 
D

Default User

santosh said:
Default User wrote:
That's a good question. What about something like:


char s[] = "";

for(;*s;)
printf("Yup, the bug is still here.\n");

The "bug" doesn't appear, both for global and local s.
That seems common enough that it should have turned up in common
usage.

The bug seems to be produced only with a numeric literal. There may be
other possibilities too, but whose's going to bother testing
exhaustively such an outdated compiler/s.

Ok, that makes more sense. That's a fairly unlikely construct in "real"
code, so I'm not too surprised they didn't catch it. Keith's suggestion
of an optimization bug is possible.



Brian
 
S

santosh

Kenneth said:
santosh wrote:
[...]
Does the bug only occur with "for(;0;)"? What about: [...]
The bug seems to be produced only with a numeric literal. There may be
other possibilities too, but whose's going to bother testing
exhaustively such an outdated compiler/s.

I'll bet it's an optimization gone awry. The author(s) probably tried
to optimize the case of a constant condition and got the logic
backwards.

I wonder whether "for (;1;)" also misbehaves.

Nope. It results in an infinite loop as it should. Thus far it only
seems to occur for literal constant 0. I'm rather surprised though that
nobody seems to have spotted it in about 15 years.

Well, the bug was fixed in a later release, either intentionally (because
someone found it) or unintentionally (in which case it was no longer there
to be "spotted").

In either case, how often does one write "for(;0;)"? (BTW, does "while(0)"
fail the same way?)

No. Works correctly.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top