Martin G C Davies wrote:
Now I have bumped into a difference (I have an easy workaround for me real code but I thought people might be interested).
Build and run the program below.
program mgcd_program;
var num : integer ;
begin num := -2147483648 ;
if num = 16#80000000 then
writeln( 'equal' ) else writeln( 'not equal' ) end.
When I build with
gpc version 2.1 (20020510), based on gcc-2.8.1
I get the output "equal".
When I build with
gpc version 20021128, based on gcc-3.2.1
I get the output "not equal".
The C program:-
main() { int num = -2147483647 - 1 ;
if ( num == 0x80000000 )
printf( "equal\n" ) ; else printf( "not equal\n" ) ; }
always returns "equal".
Anyway, clearly there is an inconsistency between the GPC versions.
Indeed, but since in Pascal "not equal" is correct, I'm glad it's so. I suppose it's the result of the following bug fix:
@item 20020904: comparisons between signed and unsigned integers sometimes give wrong results (eike2.pas, fjf664.pas)
According to C semantics, I guess "equal" is correct (since it silently ignores overflows, AFAIK). (At least on 32 bit systems. If int is 64 bits, it would probably be "not equal", too.)
Frank