Path: utzoo!attcan!uunet!van-bc!rsoft!mindlink!a665 From: a665@mindlink.UUCP (Anthon Pang) Newsgroups: comp.sys.amiga Subject: Re: Amiga Modula-2 News/Comments/Info Message-ID: <2064@mindlink.UUCP> Date: 10 Jun 90 07:21:47 GMT Organization: MIND LINK! - British Columbia, Canada Lines: 65 > jcs@crash.cts.com writes: > Allocating memory (using AllocMem) *is* the solution. You can declare > your type as ARRAY[0..1] of mydata and don't use range checking (who does?). > The compiler will generate the correct code, all it needs to know is the > size of your data. > If the compiler does something like: > > add.w d0,d0 > add.w d0,d0 > > or > > lsl.w #2,d0 > > to do a *4 index for your array, then 64k is still a limit. I guess you've never disassembled the binaries generated by the Benchmark compiler/linker. The interpretation of the 64K limit depends on context... ...in the case of arrays, it is either the size of the data structure (64K bytes), or the range of the array index [0..65536]. With open arrays, the index limit is 65535 elements. With fixed arrays, the compiler WILL check against the VAR declaration. So, I say again, AllocMem'ing is NOT "the solution". (* The following code fragment will not compile with Benchmark M2, nor is it supposed to...its purpose is to demonstrate the "limits" of the compiler *) MODULE foo; FROM SYSTEM IMPORT ADDRESS; FROM Memory IMPORT AllocMem, MemReqSet, MemFast, MemClear; CONST s = 100000D; TYPE r = [0..1]; a = ARRAY r of CARDINAL; p = POINTER TO a; VAR x : p; PROCEDURE bar(z: ARRAY OF CARDINAL); BEGIN z[65535] := 2; (* yeah, but you disabled range checking *) z[65536] := 3; (* Illegal, index exceeds 2^16=65535 *) END bar; BEGIN x := AllocMem(s,MemReqSet{MemFast,MemClear}); x[32767] := 0; (* Illegal, index exceeds TYPE'd range *) x[65535] := 1; (* Illegal, index exceeds 2^15=32768 *) bar(x^); FreeMem(x,s); END test. -- _-=^=-_ |' ^ `| Ahhh! Multiple CLIs...a copy of K&R...a can of prune #\_ ^ _/# juice...the signs of a Klingon C programmer. #' ~T~ `# #\ /-\ /# GGRRR! But, where is your ridge?! your mark of __##\#//##___ ascension into the ranks of KlinGuru?! And, where @O@ \_/ \ are the Rom Kernel Manuals, you were supposed to @#@ A | to drop on your head?! Copyright 1990 Yet Another Stupid Sig Inc.