By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,405 Members | 1,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,405 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.