Topic: Expression with Relational and Equality Operators
Author: tom@sec-world.co.uk (Tom Platts-Mills)
Date: 1999/02/03 Raw View
On 03 Feb 99 17:05:13 GMT, Ahn Ki-yung <kyagrd@daidun.kaist.ac.kr>
wrote:
>I wanted to know the type of an expression with
>relational and equality operators. So I check
>it with some available compilers with the code below.
>
>#include <typeinfo>
>#include <iostream>
>using namespace std;
>
>void main()
>{
> cout<<typeid( 1==0 ).name() <<endl;
>}
>
>Visual C++ 6.0, the result is
>long
>
>gcc version 2.8.1 (DJGPP), the result is
>b
>(b stands for bool;gcc outputs only first letter of the built in type)
>
>Isn't gcc right in this case ? (though output is not standard)
>
>I want to know type of such expressions by default.
>Is it defined in standard ?
Yes, the result of relational expressions ( < > <= == != etc.) have
the type bool. VC6 still has the old behaviour, returning type int,
which you have to be aware of. ints will implicitly cast to bool
where necessary, but you can run into trouble, e.g. with functions
overloaded by bool and int types, and functions requiring implicit
conversions from bool to another type.
>Or is it dependant to compiler ? (which means undfined)
Tom Platts-Mills
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 1999/02/04 Raw View
In article <36B841D9.45FF0471@daidun.kaist.ac.kr>, Ahn Ki-yung
<kyagrd@daidun.kaist.ac.kr> writes
>I want to know type of such expressions by default.
>Is it defined in standard ?
>Or is it dependant to compiler ? (which means undfined)
1) the comparison operators return bool.
2) dependant on a compiler would be implementation defined which is
distinctly different from 'undefined'
Francis Glassborow Chair of Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1999/02/04 Raw View
Ahn Ki-yung <kyagrd@daidun.kaist.ac.kr> writes:
>I wanted to know the type of an expression with
>relational and equality operators. So I check
>it with some available compilers with the code below.
They are type boolean according to the standard, but not
all compilers implement that rule yet. Prior to the standard
they were defined to have type int, the same as in C.
--
Steve Clamage, stephen.clamage@sun.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Ahn Ki-yung <kyagrd@daidun.kaist.ac.kr>
Date: 1999/02/03 Raw View
I wanted to know the type of an expression with
relational and equality operators. So I check
it with some available compilers with the code below.
#include <typeinfo>
#include <iostream>
using namespace std;
void main()
{
cout<<typeid( 1==0 ).name() <<endl;
}
Visual C++ 6.0, the result is
long
gcc version 2.8.1 (DJGPP), the result is
b
(b stands for bool;gcc outputs only first letter of the built in type)
Isn't gcc right in this case ? (though output is not standard)
I want to know type of such expressions by default.
Is it defined in standard ?
Or is it dependant to compiler ? (which means undfined)
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]