On 07.03.2010, at 21:07, Albrecht Schlosser wrote:

> On 07.03.2010, at 20:55, Greg Ercolano wrote:
>> Domingo Alvarez Duarte wrote:
> ...
>>> output on my machine: 00403000 = 00403000 = 00403000
>> 
>>      It depends on the compiler.
>> 
>>      g++ behaves as above, but for instance with Microsoft VS 7 I get:
>> 
>> Z:\tmp>cl /TP foo.cxx
>> Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.00.9466 for 80x86
>> Copyright (C) Microsoft Corporation 1984-2001. All rights reserved.
>> 
>> foo.cxx
>> Microsoft (R) Incremental Linker Version 7.00.9955
>> Copyright (C) Microsoft Corporation.  All rights reserved.
>> 
>> /out:foo.exe
>> foo.obj
>> 
>> Z:\tmp>.\foo.exe
>> 00408040 = 00408048 = 00408050
>>      ^^         ^^         ^^
> 
> One more reason not to use the MS compilers ;-P

It is actually a compile time option. Early versions of C/C++ allowed strings 
to be char* (instead of const char*). As a result, programmers would modify 
those strings, even though they were supposed to be read-only. Now if you 
re-use the same string at compile time, but the programmer expects them to be 
different strings and modifies one, all other ones will obviously be modified 
as well. 

Microsoft decided that old software should run as expected, the gcc team 
instead triggers a segmentation fault. Both philosophies have their advantages 
- I guess. At least VC has a compiler flag that allows the reuse of identical 
read-only strings.
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to