Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Seg fault problems on 64bit linux

Author: Robert Hyatt

Date: 11:44:58 09/05/05

Go up one level in this thread


On September 05, 2005 at 12:07:15, Andreas Guettinger wrote:

>On September 05, 2005 at 10:12:38, Robert Hyatt wrote:
>>
>>
>>One probable issue is pointers are 64 bits, while ints are not.  If someone is
>>fooling around using pointers, there can be issues...
>
>Could you post an example of a pointer opearation that would break?
>
>regards
>Andy

anything that believes that a "pointer == int" can break.  Some compilers will
warn, unless you cast things properly.  But that doesn't mean they won't
break...

Here is one example where you want to malloc() something, then be sure that it
is on a 64 byte alignment to map into cache optimally:

    void *p = (void *) ((int) malloc(size+63) + 63) & ~63);

What I do is malloc 63 bytes more than I need, add 63 to the resulting pointer,
then and with a constant (an int unfortunately) that has the rightmost 6 bits of
zero to force the address to a 64 byte boundary.  But the address could well be
beyond 2^32 on a 64 bit architecture, and you just destroyed the upper 32 bits
by setting them all to zero in the conversion...

There are other ways as well, but the basic problem always revolves around int =
32 bits, pointer (and long) = 64 bits...  Why an int is 32 bits on a 64 bit
machine is a good question.  We really needed some better int types, but the
ANSI C committee failed to deliver them.  int16, int32, int64 would have been a
bit clearer.  Or else on 64 bit machines, int = 64 bits, which is what happens
on the Cray at least... and also on the alpha...




This page took 0.01 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.