C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problems with ....hmm, linker perhaps

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Patrick Kowalzick
Guest





PostPosted: Fri Oct 29, 2004 11:23 am    Post subject: Problems with ....hmm, linker perhaps Reply with quote



Dear all,

IMO the following program is legal and should compile.

//***** code start *********
// Definition of class A
template <typename T> struct A
{
typedef T value_type;
};

// Definition of class B
template <typename> struct B {};

// Function foo
// returntype important !
template <typename T>
B<typename T::value_type> foo()
{
return B<typename T::value_type>();
};

int main()
{
typedef B< int >( * ptr )(); // Function pointer

ptr foo_ptr = foo< A; // Initialization of function pointer

return 0;
}
//***** code end *********

It builds fine with g++ and MSVC7.1, but the latter one fails linking:

unresolved external symbol "struct B<int> __cdecl foo<struct A(void)"
(??$foo@U?$A@H@@@@YA?AU?$B@H@@XZ) referenced in function _main

what I do not really understand. It is getting a lit more weird now. If I
change

ptr foo_ptr = foo< A;

to

ptr foo_ptr ;
foo_ptr = foo< A;

it compiles and links fine as well with MSVC 7.1.

Before I blame anyone, I want to ask if I overlooked something? IMO the code
is fine.

Regards,
Patrick



Back to top
JKop
Guest





PostPosted: Fri Oct 29, 2004 11:56 am    Post subject: Re: Problems with ....hmm, linker perhaps Reply with quote




Quote:
If I change

ptr foo_ptr = foo< A;

to

ptr foo_ptr ;
foo_ptr = foo< A;

it compiles and links fine as well with MSVC 7.1.


Well, without scrutanizing your code too much, the only difference in the
above is that the former calls a constructor, while the latter calls the
default constructor and then calls operator=.


-JKop

Back to top
Thomas Maier-Komor
Guest





PostPosted: Fri Oct 29, 2004 11:57 am    Post subject: Re: Problems with ....hmm, linker perhaps Reply with quote



Patrick Kowalzick wrote:
Quote:
Dear all,

IMO the following program is legal and should compile.

//***** code start *********
// Definition of class A
template <typename T> struct A
{
typedef T value_type;
};

// Definition of class B
template <typename> struct B {};

// Function foo
// returntype important !
template <typename T
B {
return B<typename T::value_type>();
};

int main()
{
typedef B< int >( * ptr )(); // Function pointer

ptr foo_ptr = foo< A; // Initialization of function pointer

return 0;
}
//***** code end *********

It builds fine with g++ and MSVC7.1, but the latter one fails linking:

unresolved external symbol "struct B<int> __cdecl foo<struct A(void)"
(??$foo@U?$A@H@@@@YA?AU?$B@H@@XZ) referenced in function _main

what I do not really understand. It is getting a lit more weird now. If I
change

ptr foo_ptr = foo< A;

to

ptr foo_ptr ;
foo_ptr = foo< A;

it compiles and links fine as well with MSVC 7.1.

Before I blame anyone, I want to ask if I overlooked something? IMO the code
is fine.

Regards,
Patrick


compiles and links fine with Sun Studio 9...

Back to top
Patrick Kowalzick
Guest





PostPosted: Fri Oct 29, 2004 12:02 pm    Post subject: Re: Problems with ....hmm, linker perhaps Reply with quote

Quote:
compiles and links fine with Sun Studio 9...

Thx.



Back to top
Unforgiven
Guest





PostPosted: Fri Oct 29, 2004 12:06 pm    Post subject: Re: Problems with ....hmm, linker perhaps Reply with quote

"Patrick Kowalzick" <Patrick.Kowalzick (AT) cern (DOT) ch> wrote

Quote:
Dear all,

IMO the following program is legal and should compile.

I concur with your opinion. I tested and verified that VC7.1 does not. I
think it's not a problem with the linker though, it looks as if the compiler
isn't instantiating the foo<A template, so when the linker looks for
it, it finds nothing.

I also tested this under Visual C++ 2005 (VC8) beta 1
([url]http://lab.msdn.microsoft.com/vs2005/)[/url], and it compiles and links fine,
which seems to suggest this is indeed a bug in VC7.1 which has been fixed
for VC8.

--
Unforgiven



Back to top
Patrick Kowalzick
Guest





PostPosted: Fri Oct 29, 2004 12:08 pm    Post subject: Re: Problems with ....hmm, linker perhaps Reply with quote

Hi JKop,

Quote:
If I change

ptr foo_ptr = foo< A;

to

ptr foo_ptr ;
foo_ptr = foo< A;

it compiles and links fine as well with MSVC 7.1.


Well, without scrutanizing your code too much, the only difference in the
above is that the former calls a constructor, while the latter calls the
default constructor and then calls operator=.

[answer for JKop]
Bullshit.

[answer for the rest]
I doubt that for function pointers constructors must be called. Is this
compiler dependent? Whats the terminology for built-in types?

Reagrds,
Patrick



Back to top
Patrick Kowalzick
Guest





PostPosted: Fri Oct 29, 2004 12:11 pm    Post subject: Re: Problems with ....hmm, linker perhaps Reply with quote

Dear Unforgiven,

Quote:
IMO the following program is legal and should compile.

I concur with your opinion. I tested and verified that VC7.1 does not. I
think it's not a problem with the linker though, it looks as if the
compiler
isn't instantiating the foo<A template, so when the linker looks
for
it, it finds nothing.

I also tested this under Visual C++ 2005 (VC8) beta 1
([url]http://lab.msdn.microsoft.com/vs2005/)[/url], and it compiles and links fine,
which seems to suggest this is indeed a bug in VC7.1 which has been fixed
for VC8.

Thanks a lot.

So it seems that I have to search a workaround for my application Sad, which
has a little bit different structure compared to the testcase.

Patrick



Back to top
JKop
Guest





PostPosted: Fri Oct 29, 2004 12:19 pm    Post subject: Re: Problems with ....hmm, linker perhaps Reply with quote


Quote:
[answer for JKop]
Bullshit.


Perhaps I should be more general:


A) AnyClass blah = some_expression;

This calls a contructor, supplying "some_expression" as an argument.


B) AnyClass blah; blah = some_expression;


This calls the default constructor. It then calls operator=.


Use your own intelligence to see what I'm getting at.


-JKop

Back to top
Patrick Kowalzick
Guest





PostPosted: Fri Oct 29, 2004 12:29 pm    Post subject: Re: Problems with ....hmm, linker perhaps Reply with quote

Quote:
[answer for JKop]
Bullshit.

Yep.

Quote:

Perhaps I should be more general:


A) AnyClass blah = some_expression;

This calls a contructor, supplying "some_expression" as an argument.


B) AnyClass blah; blah = some_expression;


This calls the default constructor. It then calls operator=.

You are talking about classes, don't you?
See the OP, I was talking about function pointers.

Regards,
Patrick




Back to top
Richard Herring
Guest





PostPosted: Fri Oct 29, 2004 12:38 pm    Post subject: Re: Problems with ....hmm, linker perhaps Reply with quote

In message <5zqgd.40415$Z14.14642 (AT) news (DOT) indigo.ie>, JKop <NULL (AT) NULL (DOT) NULL>
writes
Quote:

[answer for JKop]
Bullshit.


Perhaps I should be more general:


A) AnyClass blah = some_expression;

This calls a contructor, supplying "some_expression" as an argument.


B) AnyClass blah; blah = some_expression;


This calls the default constructor. It then calls operator=.


Use your own intelligence to see what I'm getting at.


What is the type of foo_ptr?

--
Richard Herring

Back to top
Rob Williscroft
Guest





PostPosted: Fri Oct 29, 2004 12:56 pm    Post subject: Re: Problems with ....hmm, linker perhaps Reply with quote

Patrick Kowalzick wrote in news:clt96o$icc$1 (AT) sunnews (DOT) cern.ch in
comp.lang.c++:

Quote:
int main()
{
typedef B< int >( * ptr )(); // Function pointer

ptr foo_ptr = foo< A; // Initialization of function pointer

return 0;
}
//***** code end *********

It builds fine with g++ and MSVC7.1, but the latter one fails linking:

unresolved external symbol "struct B<int> __cdecl foo<struct A (void)" (??$foo@U?$A@H@@@@YA?AU?$B@H@@XZ) referenced in function
_main



This is a bug in MSVC 7.1, Its "forgoten" to do the implicit
instantiation of foo< A< int > >.

I haven't seen it in precisly this context (taking a function pointer)
but in a few other's I have.

As a minor data point I compiled with:

cl -nologo -Za -Zc:forScope,wchar_t -EHsc -O1 -ML -Tptest.cpp

and msvc *didn't* exhibit the problem, but if I compiled:

cl test.cpp

I got the unresolved external, I don't know which combination of
option's achived this turnaround or why.

Rob.
--
http://www.victim-prime.dsl.pipex.com/

Back to top
Andrey Tarasevich
Guest





PostPosted: Fri Oct 29, 2004 5:07 pm    Post subject: Re: Problems with ....hmm, linker perhaps Reply with quote

Patrick Kowalzick wrote:
Quote:
...
int main()
{
typedef B< int >( * ptr )(); // Function pointer

ptr foo_ptr = foo< A; // Initialization of function pointer

return 0;
}
//***** code end *********

It builds fine with g++ and MSVC7.1, but the latter one fails linking:

unresolved external symbol "struct B<int> __cdecl foo<struct A(void)"
(??$foo@U?$A@H@@@@YA?AU?$B@H@@XZ) referenced in function _main
...

Seems to be a compiler problem. Try using the address-of operator explicitly

ptr foo_ptr = &foo< A;

I remember that sometimes it helped to solve similar problems in MSVC++
6, but I don't know whether it will help in MSVC++ 7.

Explicit instantiation will probably also solve the problem, but that
would be a high-maintenance solution.

--
Best regards,
Andrey Tarasevich

Back to top
Ron Natalie
Guest





PostPosted: Fri Oct 29, 2004 7:28 pm    Post subject: Re: Problems with ....hmm, linker perhaps Reply with quote

There is a known bug in visual studio 6 when defining
function templates that don't have the templated variables
in their signature.
Back to top
Patrick Kowalzick
Guest





PostPosted: Mon Nov 01, 2004 8:45 am    Post subject: Re: Problems with ....hmm, linker perhaps Reply with quote

Hi Andrey,

Quote:
Seems to be a compiler problem. Try using the address-of operator
explicitly

ptr foo_ptr = &foo< A;

same problem,...

Quote:
I remember that sometimes it helped to solve similar problems in MSVC++
6, but I don't know whether it will help in MSVC++ 7.

Explicit instantiation will probably also solve the problem, but that
would be a high-maintenance solution.

but while I get around it like this:

ptr foo_ptr;
foo_ptr = &foo< A;

it is ok for now Smile. I documented in my code as a bug. Shall be enough....

Thanks,
Patrick



Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.