What if you define your variable as -32767..32767, instead of -32768..32767? Does that work?
I know that the full range of a 16 bit, two's complement integer is indeed -32768..32767, but Pascal does not assume two's complement implementation, hence the range for an integer is -maxint..maxint, not -(maxint+1)..maxint. Therefore, GPC may at least in some cases regard the need for -32768 as an integer type whose maxint is 32768 or greater, in which case 16 bits would be deemed inadequate (with 32 bits chosen instead).
If the above analysis is true, then GPC has two bugs : 1. It is inconsistent about whether -32768..32767 fits within 16 bits. 2. It is allowing the "external" qualifier to circumvent checking for duplicate identifiers (as Maurice has already pointed out).
Joe.
-----Original Message----- From: Martin G C Davies [SMTP:martin.g.c.davies@ntlworld.com] Sent: Wednesday, January 16, 2002 10:54 PM To: gpc@gnu.de Subject: Re: Is this a bug or me being stupid?
-----Original Message----- From: gpc-owner@gnu.de [mailto:gpc-owner@gnu.de]On Behalf Of Maurice Lombardi Sent: 16 January 2002 10:47 To: gpc@gnu.de Subject: Re: Is this a bug or me being stupid?
Martin G C Davies wrote:
main: sizeof curpseudoreg=2 main: alignof curpseudoreg=2 main: curpseudoreg initially set to 5 initregcons: sizeof curpseudoreg=4 initregcons: alignof curpseudoreg=4 initregcons: curpseudoreg=327680 initregcons: curpseudoreg now set to 99 main: curpseudoreg=0
So the quuestion is, why is the sizeof and alignog different in the
two
modules?
They are not the same variable. You see that the values also of curpseudoreg are different.
Thanks for the analysis Maurice but I don't think it's correct for three reasons:-
- If I change packed -32768..32767 to integer(16) the problem goes away
for the example given.
- I added a writlen of the addr of curpseudoreg and it is the same
address in each module (new code below).
- 327680 is hex 50000 so it just looks like the sizeof and alignof of 4
are what is mucking it up.
Thus I still think this a gpc bug.
main.pas
program main(output) ;
procedure initregcons ; external ;
var curpseudoreg : packed -32768..32767number ; external ;
begin writeln( 'main: addr curpseudoreg=' , integer( addr( curpseudoreg ) ) ) ; writeln( 'main: sizeof curpseudoreg=' , sizeof( curpseudoreg ) ) ; writeln( 'main: alignof curpseudoreg=' , alignof( curpseudoreg ) ) ; curpseudoreg := 5 ; writeln( 'main: curpseudoreg initially set to ' , curpseudoreg ) ; initregcons ; writeln( 'main: curpseudoreg=' , curpseudoreg ) ; end.
regabs.pas
module regabs ;
var curpseudoreg : packed -32768..32767 ; external ; var curpseudoreg : packed -32768..32767 ;
procedure initregcons ; external ;
procedure initregcons ; begin writeln( 'initregcons: addr curpseudoreg=' , integer( addr( curpseudoreg ) ) ) ; writeln( 'initregcons: sizeof curpseudoreg=' , sizeof( curpseudoreg ) ) ; writeln( 'initregcons: alignof curpseudoreg=' , alignof( curpseudoreg ) ) ; writeln( 'initregcons: curpseudoreg=' , curpseudoreg ) ; curpseudoreg := 99 ; writeln( 'initregcons: curpseudoreg now set to ' , curpseudoreg ) ; end ;
end.
and the output when run is:-
main: addr curpseudoreg=522892 main: sizeof curpseudoreg=2 main: alignof curpseudoreg=2 main: curpseudoreg initially set to 5 initregcons: addr curpseudoreg=522892 initregcons: sizeof curpseudoreg=4 initregcons: alignof curpseudoreg=4 initregcons: curpseudoreg=327680 initregcons: curpseudoreg now set to 99 main: curpseudoreg=0