Article View: comp.sys.atari.st
Article #41499(none)
From: ULAMMERS
Date: Fri, 02 Mar 1990 18:29
Date: Fri, 02 Mar 1990 18:29
65 lines
2534 bytes
2534 bytes
Date: 02 March 1990, 18:25:30 GMT
From: ULAMMERS at DOSUNI1
To: INFO-ATARI16@WSMR-SIMTEL20.ARMY.MIL
Subject: Re: Turbo C v1.0 bug? -- NO!
In article <870@tnosoes.UUCP> mcsun!hp4nl!tnosoes!joep@uunet.uu.net
(Joep Mathijssen) writes:
>|| #include <stdio.h>
>||
>|| long tab[9000];
>||
>|| main()
>|| {
>|| int i;
>|| long j;
>||
>|| i = 0x2000; /* 0x2000 = 8192 */
>|| j = 0x2000L;
>|| fprintf(stderr, "%lx, %lx\n", &(tab[i]), &(tab[j]));
>|| }
>||
>||
>
>RESULT:
>
>|| 561b2, 661b2
>
>Can anybody explain the difference in the result when using an 'int' or
>'long int' as array-index?
>
>Joep,
>
>PS: don't tell me this is a feature!
Ok, I'm not going to tell you this is a feature but it isn't neither
a bug. The keypoint is, that in order to access an element of a vector
larger than 32K (this is true for tab) you m u s t always use
a long index. For the program above Turbo-C generates something like this:
...
lea tab,a2 ; a2 contains vector base address
move.w #$2000,d3 ; i=0x2000;
move.l #$2000,d4 ; j=0x2000L;
move.l a2,a0
move.l d4,d0
lsl.l #2,d0 ; muliply d0 by 4 == sizeof(long)
add.l d0,a0 ; a0=&tab[j]
move.l a0,-(sp) ; push a0 for printf
move.l a2,a0
move.w d3,d0
lsl.w #2,d0 ; some as above, but now: bits 14 and 15 are lost
; this means d0.w will be 0 now.
add.w a0,d0 ; a0=&tab[0] !!!!!
move.l a0,-(sp) ; push a0 for printf
...
So, the calculation of &tab[i] failed because 0x2000*4 > 32K and this is
too large for an int.
BTW, the information to use long indices in conjunction with large vectors
is already included in the README-file that comes along with the compiler.
+++++++++++++++++++++++++++++++++++++++++++++++++++
+ Uwe Lammers +
+ Univerity of Osnabrueck, Departement of Physics +
+ Email: ULAMMERS@DOSUNI1.BITNET +
+ Send flames to /dev/null +
+++++++++++++++++++++++++++++++++++++++++++++++++++
Technical Details
Message-ID:
<9003030804.AA24624@ucbvax.Berkeley.EDU>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!mips!apple!agate!ucbvax!DOSUNI1.BITNET!ULAMMERSShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!mips!apple!agate!ucbvax!DOSUNI1.BITNET!ULAMMERS From: ULAMMERS@DOSUNI1.BITNET Newsgroups: comp.sys.atari.st Subject: (none) Message-ID: <9003030804.AA24624@ucbvax.Berkeley.EDU> Date: 2 Mar 90 18:29:31 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 65