qingning wrote:
Quote:
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.
Quote:
>
--cut--
$ cat constf2.cc
void f(const int);
>
void f(int)
{
}
Move this function definition below 'main', what do you get?
Quote:
>
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