Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Solaris 8-10: data types: stronger as Linux and Windows ?

Author: Eugene Nalimov

Date: 10:36:34 10/25/05

Go up one level in this thread


On October 25, 2005 at 09:53:51, Gerd Isenberg wrote:

>On October 25, 2005 at 08:39:07, Daniel Mehrmannn wrote:
>
>>Hi,
>>
>>well i found a bug in my engine. I declare the boolean variable "stop_search" in
>>search.c. I made the error that i call this variable as "extern int stop_search"
>>from other files.
>>
>>Interesting:
>>- No compiler found this error (gcc, icc, vc 6.0  (also solaris))
>>- On Windows and Linux(!) the engine runs without any problems.
>>
>>Expect Solaris 8-10 (Sparc) family created a "segmentation fault" at first
>>access.
>>
>>How is this possible ? Why other plattforms and compiler ignored this problem ?
>>I only do a read access of this extern variable.
>>
>>see here: http://www.homer-chess.com/images/sol9.jpg
>>
>>Best,
>>Daniel
>
>Hi Daniel,
>
>it depends where the linker "allocates" the boolean variable with sizeof one
>byte. If it is "near" a 4K-Page boundary (1000h), let say at 0xffe or 0xfff, a
>byte read/write is fine, while an "external" dword read will crash.
>
>Did you do the external declaration inside a shared header file (i guess no)?
>Imagine the extern declaration is included from a shared h file,
>
>extern int foo;
>bool foo;
>
>then the compiler recognizes the error:
>error C2371: 'foo' : redefinition; different basic types
>
>while this is fine:
>
>extern bool foo;
>bool foo;
>
>Otherwise with disjoint declaration in C-files the compiler has no chance to
>detect the error, while the linker is probably overstrained with type checking
>of symbols (probably one reason that C++ names put some type information to
>symbols).
>
>Gerd

In Visual C 8.0 we will recognize such case and give you warning if the program
is compiled with link-time code generation (/GL compiler flag).

Thanks,
Eugene

t1.c:

    typedef char bool;
    bool c;

t2.c:

    #include <stdio.h>

    extern int c;

    int main ()
    {
        printf ("%p\n", &c);
        return 0;
    }

D:\repro>cl /Ox /GL t1.c t2.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.34 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

t1.c
t2.c
Microsoft (R) Incremental Linker Version 8.00.50727.34
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:t1.exe
/ltcg
t1.obj
t2.obj
warning C4742: 'c' has different alignment in 'd:\repro\t2.c' and
'd:\repro\t1.c': 4 and 1
warning C4743: 'c' has different size in 'd:\repro\t2.c' and 'd:\repro\t1.c': 4
and 1 bytes
Generating code
Finished generating code



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.