Author: Heiner Marxen
Date: 15:05:19 09/26/99
Go up one level in this thread
On September 26, 1999 at 16:25:44, Robert Hyatt wrote:
>On September 26, 1999 at 14:07:03, Heiner Marxen wrote:
>
>>On September 23, 1999 at 09:53:00, Robert Hyatt wrote:
>>
>>>On September 23, 1999 at 05:00:04, Andreas Stabel wrote:
>>[snip]
>>>>This is approx. how I have done it in my program:
>>>>
>>>>#define BITBOARD __int64
>>>>
>>>>char * outdlong(BITBOARD oval)
>>>>{
>>>> BITBOARD h1, h2;
>>>> int i, negflag;
>>>> static char obuff[32];
>>>>
>>>> i = 30; negflag = 0;
>>>> if (oval < 0) { negflag = 1; oval = -oval; }
>>>> for (;;) {
>>>> h1 = oval / 10;
>>>> h2 = oval - (h1*10);
>>>> obuff[i] = (char)(h2+ '0'); --i;
>>>> if (h1 == 0) break;
>>>> oval = h1;
>>>> }
>>>> obuff[31] = 0;
>>>> if (negflag) obuff[i] = '-'; else ++i;
>>>> return(&obuff[i]);
>>>>}
>>>>
>>>>char outbuf[...]
>>>>
>>>>sprintf(outbuff,"something %s something ...",,,,outdlong(myvar),,,);
>>>>
>>>>Of course in this implementation you should be careful not to use the
>>>>outdlong routine twice without copying the output string since the static
>>>>variable obuff will be overwritten.
>>>>
>>>>Regards
>>>>Andreas Stabel
>>>
>>>
>>>that works, but you can't use it twice in one printf()... ie in my case, I
>>>would need multiple 64 bit ints, one for nodes, one for evals done, one for
>>>hash probes, one for pawn hash probes, several for search extensions... you
>>>have to print such lists one entry at a time because of the static buffer you
>>>use. I do this for "DisplayEvaluation()" and it is a headache...
>>
>>That can be solved. Say, you want at most 8 such conversions to be used
>>in one printf (between 2 sequence points). Just use an 8-element array
>>of such static string buffers, with a static index for the next to use
>>element, cyclically walking through the 8 buffers. I've done that,
>>and found it to be a great help.
>>
>>Sometimes I've used "double" for counters to achieve 53 bits of integer
>>precision, and print them with "%.0f".
>>
>>Heiner
>
>
>it would work, but it is a very sloppy programming approach. IE imagine what
>happens when you use this piece of code to display more than 8 values at one
>time when you are debugging one day. And you forget that you have that 8 number
>limit, and spend a lot of time debugging something that isn't a bug, because the
>output is corrupted...
>
>as the saying goes, "been there, done that, but _not_ doing it tomorrow..."
Yes, you are absolutely right. It is sloppy. I wanted to mention the
idea anyhow, such that everybody can choose to deal with the sloppyness,
or just plain avoid it (like you seem to prefer). At times I do such
sloppy things, document them prominently, and promise myself to never forget.
And, of course, 8 was perhaps a bit small: take something like 100.
>:)
:-) :-)
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.