- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Here is some code that was test on 4 compilers: icpc on Linux, aCC on HP-UX, CC on SUN, xlC on AIX
The code was compile without errors on HPUX aCC, SUN CC, AIX xlC, buf failed on icpc.
==========================================
Linux illin025 2.6.18-92.1.22.el5 #1 SMP Fri Dec 5 09:28:22 EST 2008 x86_64 x86_64 x86_64 GNU/Linux
Intel C++ Intel 64 Compiler Professional for applications running on Intel 64, Version 11.0 Build 20090318 Package ID: l_cproc_p_11.0.083
Copyright (C) 1985-2009 Intel Corporation. All rights reserved.
> icpc cast_test.cpp
cast_test.cpp(58): error: invalid type conversion: "unsigned long *" to "const unsigned short &"
unsigned short s2 = static_cast
^
cast_test.cpp(59): error: invalid type conversion: "const unsigned long *" to "const unsigned short &"
unsigned short s3 = static_cast
^
compilation aborted for cast_test.cpp (code 2)
// ============= cast_test.cpp =============
#include
#include
#include
bool isBigEndian()
{
unsigned short sh = 1;
char* ch = reinterpret_cast
return (0 == *ch);
}
// ---------------
void showCompiler()
{
#if defined __hpux
system ("aCC -V");
#elif defined _AIX
system ("xlC -qversion");
#elif defined __sun
system ("CC -V");
#elif (defined __linux && defined __INTEL_COMPILER)
system (" icpc -V");
#else
#error Undefined platform
#endif
}
// ---------------
void showEnv()
{
std::cout << std::endl;
system ("uname -a");
std::cout << std::endl;
showCompiler();
std::cout << std::endl;
std::cout << "sizeof(long) = " << sizeof(long) << std::endl;
std::cout << std::endl;
std::cout << "ENDIAN: " << (isBigEndian() ? "BIG" : "LITTLE") << std::endl;
std::cout << std::endl;
}
// -------------
void castTest()
{
#define SHOW(x) std::cout << std::setw(2) << std::left << #x << std::right << " = " << std::hex << std::showbase << x << std::dec << std::endl
unsigned long l = 0x13579bdf2458ace0;
unsigned short s1 = static_cast
unsigned short s2 = static_cast
unsigned short s3 = static_cast
unsigned short s4 = reinterpret_cast
unsigned short s5 = reinterpret_cast
SHOW(l);
SHOW(s1);
SHOW(s2);
SHOW(s3);
SHOW(s4);
SHOW(s5);
}
int main()
{
showEnv();
castTest();
return 0;
}
// =======================================
Regards,
Alex
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I can reproduce these errorsin version 11.1 but not 12.0. Please upgrade to 12.0 if you would like a fix for this.
Judy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page