Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Microsoft follies (visual C/C++ 6.0) Answer found. (cough, cough) :)

Author: Dieter Buerssner

Date: 14:18:28 02/08/04

Go up one level in this thread


On February 08, 2004 at 16:49:24, Omid David Tabibi wrote:

>On February 08, 2004 at 13:22:38, Dieter Buerssner wrote:
>>It is very similar to what we already have. Assume int is 16 bit (which is
>>allowed in Standard C).
>>
>>long x = 1 << 23;
>>
>>will not do what might be intended.
>>
>>long x = 1L << 23;
>>
>>will do it. The later will work on any Standard C compiler, the former not. If
>>you don't care about compilers with 16 bit int, it might still be useful. There
>>are compilers where sizeof(long) > sizeof(int), and there will probably be more
>>in the future.
>>
>
>That's why I *never* use the long variable :)
>
>Everywhere I just use int or unsigned int, and where the variable must be 32 bit
>(like some attack tables), I use a typedefed UINT32.

I don't see, what using a typedefed UINT32 buys you here. If you need to convert
a string to an UINT32 with (say) sscanf, which format specifier do you use? %u?
%lu? Or even some #define format specifier? It makes the code look horrible
(IMHO)

#define UINT32_CONV_SPEC "%u"

  UINT32 a;
  int i, j;
  sscanf(buf, "%d" UINT32_CONV_SPEC "%d", &i, &a, &j);

Many similar problems.

Do you write

  UINT32 x = 1<<23;

or

  UINT32 x = (UINT32)1<<23;

or

  UINT32 x = 1UL<<23;

If you are aware of these things already, you won't make the bug, that started
this discussion.

I don't see any advantage of using a typeded type (in the context of this
discussion - of course there are certainly places for it). If I need a typical
unsigned variable, where 16 bit may not enough, but 32 bit is, I use unsigned
long (normally). If it is an array, and space might be an issue, I used typedefs
(I worked in environments with 64 bit longs). By default (no considerations for
speed/space - just get a correct program) I use the "normal" types (assuming int
is at least but not necessarily more than 16 bits, long 32 bits).

Some functions of the Standard C library really need type long, and not any
typedefed type. For example fseek.

Regards,
Dieter



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.