Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > help me atleast now

Reply
Thread Tools

help me atleast now

 
 
Keith Thompson
Guest
Posts: n/a
 
      03-22-2006
"santosh" <> writes:
> Default User wrote:
>> 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.

--
Keith Thompson (The_Other_Keith) kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
 
 
 
santosh
Guest
Posts: n/a
 
      03-22-2006
Keith Thompson wrote:
> "santosh" <> writes:
> > Default User wrote:
> >> 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.

 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      03-22-2006
"santosh" <> writes:
> Keith Thompson wrote:
>> "santosh" <> writes:

[...]
>> > 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.


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.

--
Keith Thompson (The_Other_Keith) kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
Kenneth Brody
Guest
Posts: n/a
 
      03-22-2006
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: <private.php?do=newpm&u=>


 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      03-22-2006
santosh wrote:

> 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
 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      03-22-2006
Kenneth Brody wrote:
> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Yet more slingshot email delay - this time 17 hrs (ongoing for atleast 2 and a half weeks now) muppet NZ Computing 3 07-04-2007 08:00 AM
help me atleast now muttaa C Programming 9 03-22-2006 03:39 PM
Query : Number of Attributes under an element & atleast 1 occurence of element/Attribute kosaraju.puneeth@gmail.com XML 0 10-26-2005 07:09 AM
Strange problem!!(it is, atleast to me!!) P R Sen Java 2 10-28-2004 01:31 AM
XML Schema : How to ensure atleast one child element present ? Abhinav XML 1 07-22-2004 12:00 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57