Problem with output

S

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

Helge Kruse

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
 
A

Alf P. Steinbach

* 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
 
S

sam

* sam:








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

osmium

sam said:
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.
 
S

sam

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

Robert Fendt

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
 
S

sam

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

Jorgen Grahn

* sam: ....
....

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
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top