help me atleast now

Discussion in 'C Programming' started by muttaa, Mar 21, 2006.

  1. muttaa

    muttaa Guest

    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.............
     
    muttaa, Mar 21, 2006
    #1
    1. Advertising

  2. "muttaa" <> wrote in
    news::

    > i'm sorry for posting an incomplete code.
    >
    > here's the full listing.................
    >
    >
    > #include<stdio.h>
    >
    > #include<conio.h>


    Nonstandard header.

    > main()


    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
    --
    A. Sinan Unur <>
    (remove .invalid and reverse each component for email address)
     
    A. Sinan Unur, Mar 21, 2006
    #2
    1. Advertising

  3. muttaa

    santosh Guest

    muttaa wrote:
    > 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.
     
    santosh, Mar 21, 2006
    #3
  4. muttaa wrote:
    >
    > 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:>
     
    Kenneth Brody, Mar 21, 2006
    #4
  5. muttaa wrote:
    > 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.
     
    Martin Ambuhl, Mar 21, 2006
    #5
  6. muttaa

    Default User Guest

    santosh wrote:

    > muttaa wrote:
    > > i'm sorry for posting an incomplete code.
    > >
    > > here's the full listing.................


    [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
     
    Default User, Mar 21, 2006
    #6
  7. muttaa

    santosh Guest

    Default User wrote:
    > santosh wrote:
    >
    > > muttaa wrote:
    > > > i'm sorry for posting an incomplete code.
    > > >
    > > > here's the full listing.................

    >
    > [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.
     
    santosh, Mar 21, 2006
    #7
  8. muttaa

    Artie Gold Guest

    Martin Ambuhl wrote:
    > muttaa wrote:
    >
    >> 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.
    >
    >

    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
    --
    Artie Gold -- Austin, Texas
    http://goldsays.blogspot.com
    "You can't KISS* unless you MISS**"
    [*-Keep it simple, stupid. **-Make it simple, stupid.]
     
    Artie Gold, Mar 21, 2006
    #8
  9. muttaa

    santosh Guest

    Artie Gold wrote:
    > Martin Ambuhl wrote:
    > > muttaa wrote:
    > >
    > >> 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.
    > >
    > >

    > 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?
     
    santosh, Mar 21, 2006
    #9
  10. muttaa

    santosh Guest

    [Sorry if this is posted twice -- Google is acting up]

    muttaa wrote:
    > > i'm sorry for posting an incomplete code.
    > >
    > > here's the full listing.................

    <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.
     
    santosh, Mar 21, 2006
    #10
  11. muttaa wrote:
    > #include<stdio.h>
    >
    > #include<conio.h>


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

    > main()


    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.

    --
    BR, Vladimir
     
    Vladimir S. Oka, Mar 21, 2006
    #11
  12. muttaa

    Default User Guest

    Vladimir S. Oka wrote:

    >
    > muttaa wrote:


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


    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
     
    Default User, Mar 21, 2006
    #12
  13. Default User opined:

    > Vladimir S. Oka wrote:
    >
    >>
    >> muttaa wrote:

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

    >
    > 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
     
    Vladimir S. Oka, Mar 21, 2006
    #13
  14. muttaa

    santosh Guest

    Default User wrote:
    > Vladimir S. Oka wrote:
    >
    > >
    > > muttaa wrote:

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

    >
    > 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.
     
    santosh, Mar 21, 2006
    #14
  15. "santosh" <> writes:
    > Default User wrote:
    >> Vladimir S. Oka wrote:
    >>
    >> >
    >> > muttaa wrote:

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

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


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

    --
    Keith Thompson (The_Other_Keith) <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.
     
    Keith Thompson, Mar 21, 2006
    #15
  16. muttaa

    CBFalconer Guest

    muttaa wrote:
    >
    > 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/>
     
    CBFalconer, Mar 21, 2006
    #16
  17. santosh wrote:
    >
    > Default User wrote:
    > > Vladimir S. Oka wrote:
    > >
    > > >
    > > > muttaa wrote:

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

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


    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:>
     
    Kenneth Brody, Mar 21, 2006
    #17
  18. muttaa

    Default User Guest

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


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



    Brian
     
    Default User, Mar 21, 2006
    #18
  19. muttaa

    santosh Guest

    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:
    >
    > #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).
     
    santosh, Mar 22, 2006
    #19
  20. muttaa

    santosh Guest

    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.
     
    santosh, Mar 22, 2006
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. P R Sen
    Replies:
    2
    Views:
    371
    Andrew Thompson
    Oct 28, 2004
  2. Abhinav
    Replies:
    1
    Views:
    711
    Abhinav
    Jul 22, 2004
  3. Replies:
    0
    Views:
    511
  4. ANoobee
    Replies:
    3
    Views:
    417
  5. muttaa

    help me atleast now

    muttaa, Mar 21, 2006, in forum: C Programming
    Replies:
    9
    Views:
    279
    Richard G. Riley
    Mar 22, 2006
Loading...

Share This Page