473,484 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Compilation problem on SUN CC compiler with template in 64-bitaddressing model

Hi,

I have compilation problem on SUN CC compiler with template while
using option -m64 (64-bit addressing model).
No problem while using option -m32 (32-bit addressing model)

$ CC -V
CC: Sun C++ 5.9 SunOS_sparc Patch 124863-01 2007/07/25
Here is some C++ program

############# foo5.cpp #############
//-----
template <typename T, T N, unsigned long S = sizeof(T) * 8>
struct static_number_of_ones
{
static const T m_value = static_number_of_ones<T, N, S - 1>::m_value
>1;
static const unsigned long m_count = static_number_of_ones<T, N, S -
1>::m_count + (static_number_of_ones<T, N, S - 1>::m_value & 0x1);
};

template <typename T, T N>
struct static_number_of_ones<T, N, 0>
{
static const T m_value = N;
static const unsigned long m_count = 0;
};

//-----
template <typename T, T N>
struct static_is_power_of_2
{
static const bool m_result = (static_number_of_ones<T,N>::m_count ==
1);
};

template <unsigned long N>
struct static_number_is_power_of_2
{
static const bool m_result = (static_number_of_ones<unsigned long,
N>::m_count == 1);
};

int main(int argc)
{
int ret = 0;
if (argc 1)
{
ret += static_is_power_of_2<unsigned short, 16>::m_result;
ret += static_is_power_of_2<unsigned int, 16>::m_result;
ret += static_is_power_of_2<unsigned long, 16>::m_result;
ret += static_number_is_power_of_2<16>::m_result;
}
else
{
ret += static_is_power_of_2<unsigned short, 17>::m_result;
ret += static_is_power_of_2<unsigned int, 17>::m_result;
ret += static_is_power_of_2<unsigned long, 17>::m_result;
ret += static_number_is_power_of_2<17>::m_result;
}
return ret;
}
##################################

Compiation:
@ CC -m32 foo5.cpp
// No problem

@ CC -m64 foo5.cpp
"foo5.cpp", line 20: Error: An integer constant expression is required
here.
"foo5.cpp", line 36: Where: While specializing
"static_is_power_of_2<unsigned long, 16>".
"foo5.cpp", line 36: Where: Specialized in non-template code.
"foo5.cpp", line 26: Error: An integer constant expression is required
here.
"foo5.cpp", line 37: Where: While specializing
"static_number_is_power_of_2<16>".
"foo5.cpp", line 37: Where: Specialized in non-template code.
"foo5.cpp", line 20: Error: An integer constant expression is required
here.
"foo5.cpp", line 43: Where: While specializing
"static_is_power_of_2<unsigned long, 17>".
"foo5.cpp", line 43: Where: Specialized in non-template code.
"foo5.cpp", line 26: Error: An integer constant expression is required
here.
"foo5.cpp", line 44: Where: While specializing
"static_number_is_power_of_2<17>".
"foo5.cpp", line 44: Where: Specialized in non-template code.
4 Error(s) detected.

=========================
It seems that in 64-bit addressing model on Sun
unsigned long is not a primitive type (?)

static_is_power_of_2<unsigned int, 16>::m_result; // No compilation
problem
static_is_power_of_2<unsigned long, 16>::m_result; // Compilation
problem
P.S. No problem with that program on HP-UX in 64-bit addressing model
Compiler aCC: HP C/aC++ B3910B A.06.15 [May 16 2007]
Thanks,

Alex Vinokur
Sep 17 '08 #1
1 2642
Alex Vinokur wrote:
Hi,

I have compilation problem on SUN CC compiler with template while
using option -m64 (64-bit addressing model).
No problem while using option -m32 (32-bit addressing model)

$ CC -V
CC: Sun C++ 5.9 SunOS_sparc Patch 124863-01 2007/07/25
Hi,

sorry, but this is off-topic here: your problem is not with C++ itself,
but with a particular product from a particular vendor.
The place to talk about this would be bugs.sun.com or sun's forums, not
here.

Having said that, Sun's CC compiler doesn't compile any of my code
either; my bug reports as well as many others about templates are
acknowledged but no solution has been made available.

I'd advise to try another compiler.

Cheers,
F. Beekhof
>
Here is some C++ program

############# foo5.cpp #############
//-----
template <typename T, T N, unsigned long S = sizeof(T) * 8>
struct static_number_of_ones
{
static const T m_value = static_number_of_ones<T, N, S - 1>::m_value
>>1;
static const unsigned long m_count = static_number_of_ones<T, N, S -
1>::m_count + (static_number_of_ones<T, N, S - 1>::m_value & 0x1);
};

template <typename T, T N>
struct static_number_of_ones<T, N, 0>
{
static const T m_value = N;
static const unsigned long m_count = 0;
};

//-----
template <typename T, T N>
struct static_is_power_of_2
{
static const bool m_result = (static_number_of_ones<T,N>::m_count ==
1);
};

template <unsigned long N>
struct static_number_is_power_of_2
{
static const bool m_result = (static_number_of_ones<unsigned long,
N>::m_count == 1);
};

int main(int argc)
{
int ret = 0;
if (argc 1)
{
ret += static_is_power_of_2<unsigned short, 16>::m_result;
ret += static_is_power_of_2<unsigned int, 16>::m_result;
ret += static_is_power_of_2<unsigned long, 16>::m_result;
ret += static_number_is_power_of_2<16>::m_result;
}
else
{
ret += static_is_power_of_2<unsigned short, 17>::m_result;
ret += static_is_power_of_2<unsigned int, 17>::m_result;
ret += static_is_power_of_2<unsigned long, 17>::m_result;
ret += static_number_is_power_of_2<17>::m_result;
}
return ret;
}
##################################

Compiation:
@ CC -m32 foo5.cpp
// No problem

@ CC -m64 foo5.cpp
"foo5.cpp", line 20: Error: An integer constant expression is required
here.
"foo5.cpp", line 36: Where: While specializing
"static_is_power_of_2<unsigned long, 16>".
"foo5.cpp", line 36: Where: Specialized in non-template code.
"foo5.cpp", line 26: Error: An integer constant expression is required
here.
"foo5.cpp", line 37: Where: While specializing
"static_number_is_power_of_2<16>".
"foo5.cpp", line 37: Where: Specialized in non-template code.
"foo5.cpp", line 20: Error: An integer constant expression is required
here.
"foo5.cpp", line 43: Where: While specializing
"static_is_power_of_2<unsigned long, 17>".
"foo5.cpp", line 43: Where: Specialized in non-template code.
"foo5.cpp", line 26: Error: An integer constant expression is required
here.
"foo5.cpp", line 44: Where: While specializing
"static_number_is_power_of_2<17>".
"foo5.cpp", line 44: Where: Specialized in non-template code.
4 Error(s) detected.

=========================
It seems that in 64-bit addressing model on Sun
unsigned long is not a primitive type (?)

static_is_power_of_2<unsigned int, 16>::m_result; // No compilation
problem
static_is_power_of_2<unsigned long, 16>::m_result; // Compilation
problem
P.S. No problem with that program on HP-UX in 64-bit addressing model
Compiler aCC: HP C/aC++ B3910B A.06.15 [May 16 2007]
Thanks,

Alex Vinokur
Sep 17 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1707
by: Aman | last post by:
Hi, I'm using the g++ compiler to compile this on SunOS 5.8. I get compilation errors when I use A* as return type but none when I used void . why is this ? regards, Aman. ----------errors...
2
1446
by: pminkov | last post by:
class A { public: template<class T> void f(); }; template<class T> void A::f<T>() { } When this code is compiled, the following error is produced: error C2768: 'A::f' : illegal use of...
0
1087
by: Adriano Coser | last post by:
Hello. I'm trying to compile a DLL with Visual C++ .NET 2003 and I'm facing an error declaring template variables with prototypes. I donīt know if I'll be able to explain my scenario, but...
0
1956
by: Ganapathy | last post by:
I have COM dll code written in VC 6.0. When i tried compiling this code in VC 7, The MIDL cmpiler gets called twice. i.e. it initially compiles fully & immediately a line - 64 bit processing'...
9
1962
by: subramanian100in | last post by:
Consider the following program: #include <iostream> #include <string> #include <vector> using namespace std; template<class Tclass Vec : public vector<T> {
6
1438
by: pleexed | last post by:
hello, this is my first post in a newsgroup, i hope i do everything right :) first of all, i am sure there have been a lot of "are templates slow?" questions around, but i think what i would...
2
1833
by: subramanian100in | last post by:
consider the following program #include <iostream> using namespace std; class Rec { public: Rec(int arg = 10) : val(arg) { }
8
3618
by: Gowtham | last post by:
Hi, I am trying to write some code which acts differently when compiled on 32 bit and 64 bit machines. To identify the machine type, I am trying to find the sizeof( int ) and comparing it with 32...
5
2923
by: David Portabella | last post by:
Hello, I have the following template class: ++++++++++++++++++++++ template <class Valueclass Test { public: void f() { if (typeid(Value) == typeid(string)) cout << "Value is a string" <<...
82
2553
by: raashid bhatt | last post by:
is there any standards that tell us how c code has to be compiled into machine code
0
6953
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7105
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7144
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6813
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7214
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3046
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3041
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
592
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
235
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.