Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: CPP related question on double code (B/W)

Author: Steffen Jakob

Date: 10:11:08 11/24/03

Go up one level in this thread


On November 24, 2003 at 09:47:44, Daniel Clausen wrote:

>On November 24, 2003 at 09:44:30, Gerd Isenberg wrote:
>
>>On November 24, 2003 at 08:52:13, Daniel Clausen wrote:
>>
>>>On November 24, 2003 at 08:39:31, Reinhard Scharnagl wrote:
>>>
>>>[snip]
>>>
>>>>I thought on using templates, but they (as far as I know) are fine to
>>>>implement same algorithms to different types. But what I want to have
>>>>is to implement (nearly equal) algorithms for the same type using two
>>>>different names.
>>>
>>>The formal parameter of a template can either be a type parameter (like int,
>>>float, class XY, etc) or a constant expression. The example below illustrates
>>>the 2nd case:
>>>
>>>
>>>#include <iostream>
>>>
>>>template <int colour> void print(void)
>>>{
>>>   std::cout << colour << std::endl;
>>>}
>>>
>>>int main(void)
>>>{
>>>   print<0>();
>>>   print<1>();
>>>
>>>   return 0;
>>>}
>>>
>>>
>>>Maybe that could help?
>>>
>>>Sargon
>>
>>
>>That's interesting Daniel! Never heard of this template const feature before ;-)
>>I tried your sample, but msc++ produces only one "print" incarnation.
>>
>>   print<0>();
>>   print<1>();
>>
>>produce two "ones",
>>1
>>1
>>
>>   print<1>();
>>   print<0>();
>>
>>produces two "zeros"
>>0
>>0
>>
>>What is wrong here, did i need special template related compiler flags?
>>
>>Thanks,
>>Gerd
>
>Yeah, Steffen Jakob mentioned that problem too. Since it's perfectly valid code
>(IMHO) and works with gcc, I assume that VC++6 is simply broken here. (hey,
>there must be a reason why it's faster then gcc ;)

It is totally legal C++ code. It is known that the old VC++6 has problems with
templates and here especially with integer parameters. The Visual .NET compiler
for example gcc handle it correctly.

Best wishes,
Steffen.



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.