help me atleast now

M

muttaa

i'm sorry for posting an incomplete code.

here's the full listing.................


#include<stdio.h>

#include<conio.h>



main()

{

clrscr();

for(;0;)

printf("Gud Morning");
getch();
return 0;
}


please explain the output............

i compiled it in Turbo C++ (3.0) compiler which i'm sure enough that
it's not broken.............
 
A

A. Sinan Unur

i'm sorry for posting an incomplete code.

here's the full listing.................


#include<stdio.h>

#include<conio.h>

Nonstandard header.

int main(void)

is better.
{

clrscr();

for(;0;)

printf("Gud Morning");
getch();
return 0;
}


please explain the output............

Well, you don't show any output, do you? How can one explain what one
does not see?
i compiled it in Turbo C++ (3.0)

I don't have that specific compiler, so after getting rid of platform
specific stuff, I get this:

D:\Home\asu1\UseNet\clc> cat t.c
#include <stdio.h>

int main(void) {
for ( ; 0 ; ) {
/* Note the newline below */
printf("Gud Morning\n");
}
return 0;
}

D:\Home\asu1\UseNet\clc> gcc -Wall t.c -o t.exe

D:\Home\asu1\UseNet\clc> t.exe

D:\Home\asu1\UseNet\clc>

Does the program above actually output something on your system?

Sinan
 
S

santosh

muttaa said:
i'm sorry for posting an incomplete code.

here's the full listing.................

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
for(;0;)
printf("Gud Morning");
getch();
return 0;
}

please explain the output............

i compiled it in Turbo C++ (3.0) compiler which i'm sure enough that
it's not broken.............

It compiles here on the Turbo C++ 1.0 compiler with a warning about
unreachable code at line 13, (the printf() line), and as you say, does
execute the printf() statement.

Strange.
 
K

Kenneth Brody

muttaa said:
i'm sorry for posting an incomplete code.

here's the full listing.................

#include<stdio.h>
#include<conio.h>

main()
{
clrscr();
for(;0;)
printf("Gud Morning");
getch();
return 0;
}

please explain the output............

i compiled it in Turbo C++ (3.0) compiler which i'm sure enough that
it's not broken.............

Well, given that you don't say what the output is, it's tough to explain
it. :)

(And the use of non-standard headers and functions won't help the matter.)

Assumptions:

<conio.h> defines prototypes for the non-standard functions used below.

clrscr() is something which clears the screen.

getch() waits for a keystroke. (Probably because you are running the
program in some environment where you would lose the output once the
program terminates.)

The output is "Gud Morning", as suggested in a previous post of yours.

If all these are true, I would say the explanation is that your compiler
is broken. The printf() within the for-loop should never execute.

Strip the program down to standard features only:

==========

#include <stdio.h>

main()
{
for(;0;)
printf("Gud Morning");
getchar();
return 0;
}

==========

This program should display nothing, and wait for you to press Enter.

--
+-------------------------+--------------------+-----------------------------+
| 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]>
 
M

Martin Ambuhl

muttaa said:
i'm sorry for posting an incomplete code.

here's the full listing.................

/* let's fix it so it's actually standard C (although no compiler should
* produce code from the original with the output you claim. */

#include<stdio.h>
#if 0
#include<conio.h> /* no such standard header */
#endif


int /* main returns an int in all versions
of C; saying so has always been a
good idea, and required since 1999. */
main(void)
{
#if 0
clrscr(); /* no such standard function */
#endif
for (; 0;)
printf("Gud Morning");
#if 0
getch(); /* no such standard function */
#endif
return 0;
}
i compiled it in Turbo C++ (3.0) compiler which i'm sure enough that
it's not broken.............

If you got the output you claim from compiling this code, then your
compiler is broken. Make sure that you don't have any stray bits lying
around that your compiler might be compiling instead, and delete any
output from a previous compilation.
 
D

Default User

[snip code]
It compiles here on the Turbo C++ 1.0 compiler with a warning about
unreachable code at line 13, (the printf() line), and as you say, does
execute the printf() statement.

Strange.


I ran it on regular old Turbo C, and it showed no output.



Brian
 
S

santosh

Default said:
[snip code]
It compiles here on the Turbo C++ 1.0 compiler with a warning about
unreachable code at line 13, (the printf() line), and as you say, does
execute the printf() statement.

Strange.


I ran it on regular old Turbo C, and it showed no output.

The same here. I compiled the OP's as well as the other's versions on
Turbo C 2.01 and Turbo C++ 1.0 and only the output of the latter's
shows this broken behaviour. The Turbo C's version runs as it should.

Strange.
 
A

Artie Gold

Martin said:
/* let's fix it so it's actually standard C (although no compiler should
* produce code from the original with the output you claim. */

#include<stdio.h>
#if 0
#include<conio.h> /* no such standard header */
#endif


int /* main returns an int in all versions
of C; saying so has always been a
good idea, and required since 1999. */
main(void)
{
#if 0
clrscr(); /* no such standard function */
#endif
for (; 0;)
printf("Gud Morning");
#if 0
getch(); /* no such standard function */
#endif
return 0;
}



If you got the output you claim from compiling this code, then your
compiler is broken. Make sure that you don't have any stray bits lying
around that your compiler might be compiling instead, and delete any
output from a previous compilation.
Q: Why do I suspect the OP had a semicolon after the `for' -- and the
`code' was retyped as opposed to being cut'n'pasted?

A: I've been spending too much time around Usenet.

--ag
 
S

santosh

Artie said:
Q: Why do I suspect the OP had a semicolon after the `for' -- and the
`code' was retyped as opposed to being cut'n'pasted?

A: I've been spending too much time around Usenet.

Actually, the Turbo C++ compilers 3.0 and 1.0 *do* seem to be broken
with regard to this piece of code. I tried OP's example as well as one
of my own with the non-standard functions removed and still the same
behaviour. The plain C compiler, Turbo C 2.01, seem to compile to the
correct object code. You can download the Turbo C++ 1.0 compiler from
Borland website, (Museum section), and try out the code and verify for
yourself.

BTW, I wonder why no one spotted the compiler bug up until now?
 
S

santosh

[Sorry if this is posted twice -- Google is acting up]
<rest snipped>

<The whole post is off-topic, but since the OP keeps posting the same
thing...>

muttaa,

The problem seems to be with the Turbo C++ compilers both your 3.0
version and my 1.0 version. The pure C version, i.e. Turbo C 2.01
produces the correct executable behaviour. This shows that the above
C++ compiler versions are broken, no doubt about that. Incidentally the
latest of Borland's compilers, Borland C++ compiler 5.5 is *not* broken
in this regard. In any case, the code you posted *should not* execute
the printf() statement.

The first thing you should do is ditch the outdated and now broken
compilers and install the GNU C Compiler, gcc. It's excellent, free and
available on several platforms. You can use the DJGPP port under DOS or
MinGW under Windows. Google for them.

Then acquire a good beginner text on C, or if you have even a little
programming experience get K&R's book (2nd Ed.). That will tell you the
semantics of C's constructs and good coding practices.
 
V

Vladimir S. Oka

muttaa said:
#include<stdio.h>

#include<conio.h>

Non-standard header, and you don't really need it...

int main(void)

is preferrable.
{

clrscr();

Non-standard function, also not needed...
for(;0;)

printf("Gud Morning");

getch();

Another non-standard function, again not really needed...
return 0;
}

please explain the output............

There's nothing to explain, as there's no output. It has already been
explained to you. Zero in the test of the `for` statement makes it
never execute the `printf` line. If you don't believe us, get a good
textbook, and see for yourself.
i compiled it in Turbo C++ (3.0) compiler which i'm sure enough that
it's not broken.............

If you got anything else, your compiler surely *is* broken.
 
D

Default User

Vladimir said:
muttaa wrote:

If you got anything else, your compiler surely is broken.

Based on what Santosh has said, it seems likely that the compiler is
broken. How that particular bug could have made it out is, hmm,
surprising.



Brian
 
V

Vladimir S. Oka

Default User opined:
Based on what Santosh has said, it seems likely that the compiler is
broken. How that particular bug could have made it out is, hmm,
surprising.

Yeah, I saw it just a moment ago. It is weird. is it possible to get
TC++ 3.0 from the Museum? I may be interested in giving it a spin on a
dull and rainy day... ;-)

--
BR, Vladimir

Well, it's hard for a mere man to believe that woman doesn't have equal
rights.
-- Dwight D. Eisenhower
 
S

santosh

Default said:
Based on what Santosh has said, it seems likely that the compiler is
broken. How that particular bug could have made it out is, hmm,
surprising.

Well, just for cross-checking my word, the relevant compilers are
available at the following URL:
http://bdn.borland.com/museum

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.
 
K

Keith Thompson

santosh said:
Well, just for cross-checking my word, the relevant compilers are
available at the following URL:
http://bdn.borland.com/museum

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.

Which explains why we now live in bug-free bliss. Sometimes I almost
miss computer viruses, but of course they can no longer propagate.
 
C

CBFalconer

muttaa said:
i'm sorry for posting an incomplete code.

here's the full listing.................

#include<stdio.h>
#include<conio.h>

main()
{
clrscr();
for(;0;)
printf("Gud Morning");
getch();
return 0;
}

please explain the output............

silly blank lines snipped.

Why are you starting a new thread? conio.h is non-standard, delete
it. then delete clrscr and getch calls, which also don't exist in
standard c. Then declare main as "int main(void)". Then ensure
you copy and paste your code into your message - do not type it
in. IIRC turbo C also has the evil habit of concealing control
chars in source code, so it might pay to retype some source lines.
It might help to replace printf with puts in this thing, just in
case you change the for loop conditional to non-zero.

The output is obviously nothing. Whats to explain?

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
 
K

Kenneth Brody

santosh said:
Well, just for cross-checking my word, the relevant compilers are
available at the following URL:
http://bdn.borland.com/museum

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:

#include <stdio.h>

/* Outside of main() to avoid possible compiler optimization */
int a=1;
int b=2;

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

--
+-------------------------+--------------------+-----------------------------+
| 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

Kenneth said:
santosh wrote:

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");


That seems common enough that it should have turned up in common usage.



Brian
 
S

santosh

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

#include <stdio.h>

/* Outside of main() to avoid possible compiler optimization */
int a=1;
int b=2;

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

No it doesn't. This compiles correctly...(atleast on TC++ 1.01).
 
S

santosh

Default said:
Kenneth said:
santosh wrote:

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.
 

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

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top