473,850 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
+ 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_o f_ones
{
static const T m_value = static_number_o f_ones<T, N, S - 1>::m_value
>1;
static const unsigned long m_count = static_number_o f_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_o f_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_i s_power_of_2
{
static const bool m_result = (static_number_ of_ones<unsigne d 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_i s_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_i s_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_powe r_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<1 6>".
"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_powe r_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<1 7>".
"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 2682
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_o f_ones
{
static const T m_value = static_number_o f_ones<T, N, S - 1>::m_value
>>1;
static const unsigned long m_count = static_number_o f_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_o f_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_i s_power_of_2
{
static const bool m_result = (static_number_ of_ones<unsigne d 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_i s_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_i s_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_powe r_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<1 6>".
"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_powe r_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<1 7>".
"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
1725
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 ------------------- :6: syntax error before `*'
2
1460
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 explicit template arguments
0
1113
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 let's try. The class TSample has a pointer (my smart pointer implementation) to a IList (an indirect list based on the same smart pointers) to the type TFontCache.
0
1989
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' comes, followed by the 64 bit compilation of the IDl file. The comlpilation goes thro' the full stage and then the StdAfx.cpp is compiled. I have another similar VC 6 COM dll code that gets compiled without invoking the 64 bit processing of the...
9
1982
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
1458
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 like to know is not that general. furthermore, what i ask here may have hardly any impact on the generated code size or performance; i am not trying to micro- optimize anything, i am just curious how templates are compiled by modern compilers of...
2
1864
by: subramanian100in | last post by:
consider the following program #include <iostream> using namespace std; class Rec { public: Rec(int arg = 10) : val(arg) { }
8
3648
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 and 64. But, the compiler is complaining about syntax errors in the #if lines. Errors: 32-64.cpp:7:13: missing binary operator before '('
5
2949
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" << endl; else
82
2660
by: raashid bhatt | last post by:
is there any standards that tell us how c code has to be compiled into machine code
0
9895
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11011
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10351
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9503
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7899
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7071
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5929
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4546
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3178
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.