473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

"const int" as function parameter type

Hi,

I've encountered code declaring functions with "const int" as parameter
type, but use "int" when defining the function. This worked fine with
g++, but failed at linking time with Sun CC. The following is an
example.

--cut--
$ cat constf.h
void f(const int);

$ cat constf.cc
#include "constf.h"
void f(int)
{
}

$ cat mconstf.cc
#include "constf.h"
int main()
{
f(0);
}

$ CC constf.cc mconstf.cc
constf.cc:
mconstf.cc:
Undefined first referenced
symbol in file
void f(const int) mconstf.o
ld: fatal: Symbol referencing errors. No output written to a.out

$ CC -V
CC: Sun C++ 5.8 2005/10/13
--cut--

Is this valid c++ code? If I put everything to a single source file, CC
compiles and links fine. I am wondering whether Sun CC linker is at
fault.

--cut--
$ cat constf2.cc
void f(const int);

void f(int)
{
}

int main()
{
f(0);
}

$ CC constf2.cc
$
--cut--

Thanks for help.

qingning

Oct 18 '06 #1
2 2292
qingning wrote:
I've encountered code declaring functions with "const int" as
parameter type, but use "int" when defining the function. This
worked fine with g++, but failed at linking time with Sun CC. The
following is an example.

--cut--
$ cat constf.h
void f(const int);

$ cat constf.cc
#include "constf.h"
void f(int)
{
}

$ cat mconstf.cc
#include "constf.h"
int main()
{
f(0);
}

$ CC constf.cc mconstf.cc
constf.cc:
mconstf.cc:
Undefined first referenced
symbol in file
void f(const int) mconstf.o
ld: fatal: Symbol referencing errors. No output written to a.out

$ CC -V
CC: Sun C++ 5.8 2005/10/13
--cut--

Is this valid c++ code? If I put everything to a single source file,
CC compiles and links fine. I am wondering whether Sun CC linker is
at fault.
Don't judge too soon. Move the function definition and possibly see
it fail again. Then contact Sun Microsystems and tell them to fix
their compiler/linker.
>
--cut--
$ cat constf2.cc
void f(const int);

void f(int)
{
}
Move this function definition below 'main', what do you get?
>
int main()
{
f(0);
}

$ CC constf2.cc
$
--cut--
Yes, it's valid code. Top-level 'cv-qualifiers' do not participate in
the function type, so 'f(int const)' *should be* the same as 'f(int)'.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 18 '06 #2


On Oct 18, 2:27 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Don't judge too soon. Move the function definition and possibly see
it fail again. Then contact Sun Microsystems and tell them to fix
their compiler/linker.
I moved the body of f() after main(). It still compiles fine.

But you are right. It's the fault of CC compiler.

$ nm constf.o | c++filt
00000010 T void f(int)

$ nm mconstf.o | c++filt
U void f(const int)
00000000 A __fsr_init_value
00000010 T main
Yes, it's valid code. Top-level 'cv-qualifiers' do not participate in
the function type, so 'f(int const)' *should be* the same as 'f(int)'.
I agree that this is valid c++. Thanks.

Qingning

Oct 18 '06 #3

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

Similar topics

3
by: H. S. | last post by:
Hi, I am trying to compile these set of C++ files and trying out class inheritence and function pointers. Can anybody shed some light why my compiler is not compiling them and where I am going...
134
by: jacob navia | last post by:
Hi Suppose you have somewhere #define BOOL int and somewhere else typedef BOOL int;
1
by: liguoqiang_0121 | last post by:
Hi,all Please look program. class AA { public: void hello(); }; void AA::hello() { printf("this is class AA\n");
16
by: recover | last post by:
#include <string> #include <iostream> using namespace std; class TConst { private: string con; string uncon; public:
1
by: Claire | last post by:
"Comparison to integral constant is useless; the constant is outside the range of type 'int'" How can I fix this compiler warning, please, for the following pseudocode? int m_nError; m_nError =...
7
by: Luna Moon | last post by:
Hi all, I just couldn't get myself clear about the usage of "const" in front of and/or behind variables, pointers, classes, objects and functions... It's too confusing... any good clear...
6
by: .rhavin grobert | last post by:
hello;-) i frequently need the following construction: ReturnParam § Function() § { /...do something.../ someType var § = something; /...do something.../ return something;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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
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...

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.