hello all, today i've run into this: if i cast a double value to an unsigned int using the C style cast when passing it to printf, it's fine. however, if i use the ctor style cast, i get a compile error. in theory, these two should do the same: create a temporary unsigned int, and assign the double to it after conversion, just the syntax is different. made a little test, see attachment. plain int's are ok, but when qualified with signed/unsigned the error occurs.
i can't judge whether this is an error or not, please clarify. $ gcc -v Using built-in specs. Target: x86_64-linux-gnu Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --enable-checking=release x86_64-linux-gnu Thread model: posix gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21) regards, p
void f(int i)
{
}
void g(unsigned int j)
{
}
class X
{
public:
X(double);
};
void t()
{
// named variables with ctor syntax : all ok
int i1(1.0);
signed int i2(1.0);
unsigned int i3(1.0);
const int ci1(1.0);
const signed int ci2(1.0);
const unsigned int ci3(1.0);
// unnamed temporaries with ctor syntax
int(1.0);
signed int(1.0); // error
unsigned int(1.0); // error
const int(1.0); // error
const signed int(1.0); // error
const unsigned int(1.0); // error
// unnamed temporaries with C style cast
(signed int)(1.0);
(unsigned int)(1.0);
(const signed int)(1.0);
(const unsigned int)(1.0);
// named variable and unnamed temporary of class X
X x(1.0);
X(1.0);
const X cx(1.0);
const X(1.0);
// new ctor style casts
f(int(1.0));
f(signed int(1.0)); // error
g(unsigned int(1.0)); // error
// old c style casts
f((int)1.0);
f((signed int)1.0);
g((unsigned int)1.0);
}
signature.asc
Description: OpenPGP digital signature
