Problem with output

Discussion in 'C++' started by sam, Feb 24, 2010.

  1. sam

    sam Guest

    Hi,
    I written the program as follows :-

    #include<iostream.h>
    #include<conio.h>
    template <class t>
    t fun(t a, t b)
    {t s;
    s=a+b;
    return (s);
    }
    void main()
    {clrscr();
    int x,y,z=0;
    x=4;y=5;
    z=fun<int>(x,y);
    cout<<z;
    getch();
    }

    When I compiled this program on Turbo c++ 3.0 , I am
    getting syntax error and also i got error as follows :-
    x is assigned to a value that is never used and
    y is assigned to a value that is never used ,
    Please help me out in this.
     
    sam, Feb 24, 2010
    #1
    1. Advertising

  2. sam

    Helge Kruse Guest

    "sam" <> wrote in message
    news:...

    > template <class t>
    > t fun(t a, t b)
    > {t s;
    > s=a+b;
    > return (s);
    > }
    > void main()
    > {clrscr();
    > int x,y,z=0;
    > x=4;y=5;
    > z=fun<int>(x,y);
    > cout<<z;
    > getch();
    > }
    >
    > When I compiled this program on Turbo c++ 3.0 , I am
    > getting syntax error and also i got error as follows :-
    > x is assigned to a value that is never used and
    > y is assigned to a value that is never used ,
    > Please help me out in this.


    Does Turbo C++ 3.0 support templates? Does your project requires this old
    compiler?

    Helge
     
    Helge Kruse, Feb 24, 2010
    #2
    1. Advertising

  3. * sam:
    > Hi,
    > I written the program as follows :-
    >
    > #include<iostream.h>
    > #include<conio.h>
    > template <class t>
    > t fun(t a, t b)
    > {t s;
    > s=a+b;
    > return (s);
    > }
    > void main()
    > {clrscr();
    > int x,y,z=0;
    > x=4;y=5;
    > z=fun<int>(x,y);
    > cout<<z;
    > getch();
    > }
    >
    > When I compiled this program on Turbo c++ 3.0 , I am
    > getting syntax error and also i got error as follows :-
    > x is assigned to a value that is never used and
    > y is assigned to a value that is never used ,
    > Please help me out in this.


    Uhm, OK. Most probably the compiler issued /warnings/, but generated an
    executable anyway. The C++ language itself doesn't differentiate between
    warnings and errors, it just requires diagnostics for some things, but in
    practice a compiler will classify the diagnostics as /warnings/ (not technically
    wrong but likely to not yield the effect that you intended, or meaningless) and
    /errors/.

    A diagnostic required by the language is usually classified as /error/. In this
    case the compiler will not generate an executable. At least if it's any good.

    A diagnostic not required by the language is usually classified as /warning/. In
    this case the compiler will usually generate an executable, i.e. the compilation
    succeeds. One exception is when the compiler recognizes that it has issued a
    zillion or more warnings, whence it may give up and give you an error.

    ---

    About the code. Turbo C++ 3.0 is pretty old, but Borland did make some darned
    good tools. However, if you want to learn modern standard C++ you will benefit
    greatly from, at some point, upgrading to a more modern compiler. Turbo C++ 3.0
    was shipped long before the language was standardized in 1998. The
    standardization changed many things, and in particular, as I recall Turbo C++
    3.0 did not have standard exceptions and dealt incorrectly with virtual calls
    from constructors.

    In modern standard C++:


    > #include<iostream.h>


    This is a non-standard header. It was used before standardization. A modern
    compiler may not offer this header, but instead the standard <iostream> header
    (note the lack of filename extension).

    In standard C++ a rough equivalent of the above is

    #include <iostream>
    using namespace std;


    > #include<conio.h>


    This is non-standard header. It was common on the Windows platform.


    > template <class t>
    > t fun(t a, t b)
    > {t s;
    > s=a+b;
    > return (s);
    > }


    OK.


    > void main()


    In standard C or C++ 'main' must always have result type 'int', not 'void'.

    Some compilers still accept 'void'.

    It's a mystery why they do since it's more to type and has never been standard,
    neither for C nor C++, but people have used it so much that even C++'s creator
    Bjarne Stroustrup managed to erroneously write 'void main' in the 2nd edition of
    his "The C++ Programming Language" book -- so you're in Very Good Company, but
    don't do it. :)



    > {clrscr();
    > int x,y,z=0;
    > x=4;y=5;
    > z=fun<int>(x,y);
    > cout<<z;
    > getch();
    > }


    OK.

    It's difficult to see why the compiler should issue warnings about anything here.

    Presumably it's a quirk of the compiler; even if Borland did make very good
    tools it is a rather old, archaic compiler, and they had to design the compiler
    for "No Speed Limit" on PCs that today aren't even in the class of cell phones.


    Cheers & hth.,

    - Alf
     
    Alf P. Steinbach, Feb 24, 2010
    #3
  4. sam

    sam Guest

    On Feb 24, 4:44 pm, "Alf P. Steinbach" <> wrote:
    > * sam:
    >
    >
    >
    >
    >
    > > Hi,
    > > I written the program as follows :-

    >
    > > #include<iostream.h>
    > > #include<conio.h>
    > > template <class t>
    > > t fun(t a, t b)
    > > {t s;
    > > s=a+b;
    > > return (s);
    > > }
    > > void main()
    > > {clrscr();
    > > int x,y,z=0;
    > > x=4;y=5;
    > > z=fun<int>(x,y);
    > > cout<<z;
    > > getch();
    > > }

    >
    > > When I compiled this program on Turbo c++ 3.0 , I am
    > > getting syntax error and also i got error  as follows :-
    > >  x is assigned to a value that is never used and
    > >   y is assigned to a value that is never used ,
    > > Please help me out in this.

    >
    > Uhm, OK. Most probably the compiler issued /warnings/, but generated an
    > executable anyway. The C++ language itself doesn't differentiate between
    > warnings and errors, it just requires diagnostics for some things, but in
    > practice a compiler will classify the diagnostics as /warnings/ (not technically
    > wrong but likely to not yield the effect that you intended, or meaningless) and
    > /errors/.
    >
    > A diagnostic required by the language is usually classified as /error/. In this
    > case the compiler will not generate an executable. At least if it's any good.
    >
    > A diagnostic not required by the language is usually classified as /warning/. In
    > this case the compiler will usually generate an executable, i.e. the compilation
    > succeeds. One exception is when the compiler recognizes that it has issued a
    > zillion or more warnings, whence it may give up and give you an error.
    >
    >    ---
    >
    > About the code. Turbo C++ 3.0 is pretty old, but Borland did make some darned
    > good tools. However, if you want to learn modern standard C++ you will benefit
    > greatly from, at some point, upgrading to a more modern compiler. Turbo C++ 3.0
    > was shipped long before the language was standardized in 1998. The
    > standardization changed many things, and in particular, as I recall Turbo C++
    > 3.0 did not have standard exceptions and dealt incorrectly with virtual calls
    > from constructors.
    >
    > In modern standard C++:
    >
    >  > #include<iostream.h>
    >
    > This is a non-standard header. It was used before standardization. A modern
    > compiler may not offer this header, but instead the standard <iostream> header
    > (note the lack of filename extension).
    >
    > In standard C++ a rough equivalent of the above is
    >
    >    #include <iostream>
    >    using namespace std;
    >
    >  > #include<conio.h>
    >
    > This is non-standard header. It was common on the Windows platform.
    >
    >  > template <class t>
    >  > t fun(t a, t b)
    >  > {t s;
    >  > s=a+b;
    >  > return (s);
    >  > }
    >
    > OK.
    >
    >  > void main()
    >
    > In standard C or C++ 'main' must always have result type 'int', not 'void'.
    >
    > Some compilers still accept 'void'.
    >
    > It's a mystery why they do since it's more to type and has never been standard,
    > neither for C nor C++, but people have used it so much that even C++'s creator
    > Bjarne Stroustrup managed to erroneously write 'void main' in the 2nd edition of
    > his "The C++ Programming Language" book  --  so you're in Very Good Company, but
    > don't do it. :)
    >
    >  > {clrscr();
    >  > int x,y,z=0;
    >  > x=4;y=5;
    >  > z=fun<int>(x,y);
    >  > cout<<z;
    >  > getch();
    >  > }
    >
    > OK.
    >
    > It's difficult to see why the compiler should issue warnings about anything here.
    >
    > Presumably it's a quirk of the compiler; even if Borland did make very good
    > tools it is a rather old, archaic compiler, and they had to design the compiler
    > for "No Speed Limit" on PCs that today aren't even in the class of cell phones.
    >
    > Cheers & hth.,
    >
    > - Alf- Hide quoted text -
    >
    > - Show quoted text -


    Hi,
    Is any new version of Turbo c++ is available for download for free?
    and second thing is means my program is correct but my problem is
    i am using older version.
     
    sam, Feb 24, 2010
    #4
  5. sam

    osmium Guest

    sam wrote:

    > I written the program as follows :-

    <snip>

    I read the thread about 13:00 GMT and posted here anyway. I modernized and
    standardized the code and it compiles, no messages, and runs and produces
    the expected outpit on the DevC package.

    ---revised code---

    #include<iostream>
    #include<conio.h>
    template <class t>
    t fun(t a, t b)
    {t s;
    s=a+b;
    return (s);
    }
    int main()
    {
    //clrscr();
    int x,y,z=0;
    x=4;y=5;
    z=fun<int>(x,y);
    std::cout<<z;
    getch();
    }
    /*
    When I compiled this program on Turbo c++ 3.0 , I am
    getting syntax error and also i got error as follows :-
    x is assigned to a value that is never used and
    y is assigned to a value that is never used ,
    Please help me out in this.
    */

    I hope this list is complete. remove the .h on iostream. conio.h is OK on
    DevC but not clrscr, remove it. change return type of main from void to
    int, add std:: to cout call.

    I had a fair amount of success using templates on TC 3.1 for windows. You
    don't mention what the syntax error was, nothing leaps out at me. Unless
    there is some overriding reason I would abandon Borland, it is/was nice but
    it is just a question of time until some big problems comes up. DevC aka
    MingW aka Bloodshed is an easy transition. (aka used loosely). The
    debugger is nothing to write home about, docs are pretty sparse. Other than
    that it seems OK for light duty work.
     
    osmium, Feb 24, 2010
    #5
  6. sam

    sam Guest

    On Feb 24, 8:02 am, "osmium" <> wrote:
    > sam wrote:
    > > I written the program as follows :-

    >
    > <snip>
    >
    > I read the thread about 13:00 GMT and posted here anyway.  I modernized and
    > standardized the code and it compiles, no messages, and runs and produces
    > the expected outpit on the DevC package.
    >
    > ---revised code---
    >
    > #include<iostream>
    > #include<conio.h>
    > template <class t>
    > t fun(t a, t b)
    > {t s;
    > s=a+b;
    > return (s);}
    >
    > int main()
    > {
    >  //clrscr();
    > int x,y,z=0;
    > x=4;y=5;
    > z=fun<int>(x,y);
    > std::cout<<z;
    > getch();}
    >
    > /*
    > When I compiled this program on Turbo c++ 3.0 , I am
    > getting syntax error and also i got error  as follows :-
    >  x is assigned to a value that is never used and
    >   y is assigned to a value that is never used ,
    > Please help me out in this.
    > */
    >
    > I hope this list is complete.  remove the .h on iostream.  conio.h is OK on
    > DevC but not clrscr, remove it.  change return type of main from void to
    > int, add std:: to cout call.
    >
    > I had a fair amount of success using templates on TC 3.1 for windows.  You
    > don't mention what the syntax error was, nothing leaps out at me.  Unless
    > there is some overriding reason I would abandon Borland, it is/was nice but
    > it is just a question of time until some big problems comes up.  DevC aka
    > MingW aka Bloodshed is an easy transition.  (aka used loosely).  The
    > debugger is nothing to write home about, docs are pretty sparse.  Other than
    > that it seems OK for light duty work.


    Hi,
    When i changed fun<int>(x,y) to fun(x,y) the code
    has compiled and give me correct output. Means
    the compiler doesn't take "<int>".
     
    sam, Feb 25, 2010
    #6
  7. sam

    Robert Fendt Guest

    And thus spake sam <>
    Wed, 24 Feb 2010 20:33:06 -0800 (PST):

    > Hi,
    > When i changed fun<int>(x,y) to fun(x,y) the code
    > has compiled and give me correct output. Means
    > the compiler doesn't take "<int>".


    If I recall it correctly, explicit function template instantiation
    was added to the standard at a very late point. Meaning that in earlier implementations, the template was always instantiated based on the functions argument list, and function prototype quite often looked like this:

    template <typename return_t>
    return_t func(return_t* dummy, arg1_t arg1, arg2_2 arg2);

    and then were instantiated like this:
    func((return_t*)0, arg1, arg2);

    (Writing this from memory, hopefully not too many typos).

    Regards,
    Robert
     
    Robert Fendt, Feb 25, 2010
    #7
  8. sam

    sam Guest

    On Feb 25, 11:57 am, Robert Fendt <> wrote:
    > And thus spake sam <>
    > Wed, 24 Feb 2010 20:33:06 -0800 (PST):
    >
    > > Hi,
    > > When i changed fun<int>(x,y) to fun(x,y) the code
    > > has compiled and give me correct output. Means
    > > the compiler doesn't take "<int>".

    >
    > If I recall it correctly, explicit function template instantiation
    > was added to the standard at a very late point. Meaning that in earlier implementations, the template was always instantiated based on the functions argument list, and function prototype quite often looked like this:
    >
    > template <typename return_t>
    > return_t func(return_t* dummy, arg1_t arg1, arg2_2 arg2);
    >
    > and then were instantiated like this:
    > func((return_t*)0, arg1, arg2);
    >
    > (Writing this from memory, hopefully not too many typos).
    >
    > Regards,
    > Robert


    Thanks for this.
     
    sam, Feb 25, 2010
    #8
  9. sam

    Jorgen Grahn Guest

    On Wed, 2010-02-24, Alf P. Steinbach wrote:
    > * sam:
    >> Hi,
    >> I written the program as follows :-
    >>

    ....

    >> When I compiled this program on Turbo c++ 3.0 , I am
    >> getting syntax error and also i got error as follows :-

    ....

    > About the code. Turbo C++ 3.0 is pretty old, but Borland did make some darned
    > good tools. However, if you want to learn modern standard C++ you will benefit
    > greatly from, at some point, upgrading to a more modern compiler. Turbo C++ 3.0
    > was shipped long before the language was standardized in 1998.


    To be precise, in November 1991. That's over eighteen years ago!

    /Jorgen

    --
    // Jorgen Grahn <grahn@ Oo o. . .
    \X/ snipabacken.se> O o .
     
    Jorgen Grahn, Feb 27, 2010
    #9
    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. John Bentley

    Output / Debug window output bug?

    John Bentley, Sep 10, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    596
    John Bentley
    Sep 10, 2003
  2. chuck amadi
    Replies:
    1
    Views:
    491
    Larry Bates
    Jun 23, 2004
  3. Paul
    Replies:
    1
    Views:
    430
  4. jmr
    Replies:
    2
    Views:
    337
  5. pratap
    Replies:
    3
    Views:
    460
    James Kanze
    Jul 19, 2007
Loading...

Share This Page