Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: OT - mingw, long long, and shift operators

Author: Heiner Marxen

Date: 12:53:42 03/20/04

Go up one level in this thread


On March 20, 2004 at 13:09:53, Dieter Buerssner wrote:

>On March 20, 2004 at 10:48:04, Heiner Marxen wrote:
>
>>On March 19, 2004 at 16:43:24, Pat King wrote:
>>
>>>unsigned long long I = (unsigned long long)1 << 35; // I'm guessing this is more
>>>//portable than '1LLU'?
>>
>>You should make a typedef for your 64-bit type, like
>>
>>typedef unsigned long long	U64_t;
>>
>>U64_t I = (U64_t)1 << 35;
>
>I am not 100% sure, but I think, U64_t may be a reserved name in POSIX/XOPEN
>(and all names ending with _t). The glibc manual writes under reserved names:
>
>"Names that end with _t are reserved for additional type names."

That comes as a surprise to me.  As far as I've read the C90 standard,
there does not appear such a reserved suffix rule.  May be it is an
addition by the glibc, or a POSIX/XOPEN thing as you suggest... dunno.


>So for maximum portability, one might use another name for the typedef.

Ok, just let's avoid any name ending in _t  ;-)


>>Yes, that way (with the cast) it is more portable than the suffix with LL,
>>since you only need to get the typedef right.
>>Another portability problem is the printf format for such values.
>
>Indeed. It is easy to change one typedef, but not easy to change many printf
>format specifiers (especially, when one didn't think of it in advance). It is
>also the reason, that I was too lazy until now, to change all my counters (which
>are typically unsigned long) to avoid overflow (node counters overflow in the
>order of magnitude of one hour on a typical modern computer). If the printf were
>few, it wouldn't be a large problem. But I have them in masses (especially in
>debugging code).

Yes, exactly.  I've had the exact same problem, and not yet found a really
satisfactory solution.  One idea here is to write a conversion function

    const char* counter2str(COUNTER c);

returning a pointer into a circular collection of sufficiently large
string buffers, allocated statically.  If I use (say) 16 such buffers,
I can use up to 16 such conversion result simultaneously in one printf,
while avoiding all problems that appear with dynamic allocation.

    printf("Tried %s, hits=%s\n", counter2str(tried), counter2str(hits));

With a sufficiently short name for the conversion function this might
work ok.  When the typedef changes, we only have to adjust the conversion
function body, but not any uses of it.


>Definetly an advantage of C++ with its typesafe printing facilities.

Yes, that is true.  One of the few reasons that appear to really favor C++
over C for something like a chess program.  Yet, I stick with C.  :-O


>Regards,
>Dieter

Cheers,
Heiner



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.