[comp.lang.pascal] valid construction?

rbw@WILLIAMS.EDU (03/08/88)

Can anyone tell me if the following is a valid construction?  I want to 
know if I should get mad at my compiler or not :-)

type
    record1 = record
       ...
       end;
    record2 = record
    	...
    	array1 : array[0..maxelts] of record1;
    	...
    	end;
Needless to say, my compiler (Turbo v4, for the curious) chokes with the
message "Invalid Type".   Any clues?

-Richard Ward
rbw@cs.williams.edu
Williams College,  Williamstown, MA

douglas@reed.UUCP (P Douglas Reeder) (03/09/88)

Richard Ward asked if his program construct was valid.
It looked fine to me, so I filled out his program as follows.
It compiled without trouble here in Berkley Pascal under UNIX on our VAX.
Richard, I think it's your compiler.

program ok;

const maxelts = 999;

type
    record1 = record
       stuff : integer;
       end;
    record2 = record
    	morestuff : integer;
    	array1 : array[0..maxelts] of record1;
    	yetmorestuff : real;
    	end;

begin
end.
-- 
Doug Reeder            USENET: ...!tektronix!reed!douglas
Box 502 Reed College   BITNET: douglas@reed.UUCP
3203 S.E. Woodstock      ARPA: !tektronix!reed!douglas@Berkley
Portland, OR 97202   UNIVERSE: Local Group,Milky Way,Sol III,122 38'W 45 28'N

ralf@B.GP.CS.CMU.EDU (Ralf Brown) (03/09/88)

In article <8432@reed.UUCP> douglas@reed.UUCP (P Douglas Reeder) writes:
}Richard Ward asked if his program construct was valid.
}It looked fine to me, so I filled out his program as follows.
}It compiled without trouble here in Berkley Pascal under UNIX on our VAX.
}Richard, I think it's your compiler.
[construct deleted, you've all seen it multiple times by now]

Please consider that this is being compiled on an Intel CPU, which means
that the maximum size of any single data object is 64K.  If "maxelts" is
large enough, the size of the record can easily exceed 64K, causing the
compile-time error.
-- 
{harvard,uunet,ucbvax}!b.gp.cs.cmu.edu!ralf -=-=- AT&T: (412)268-3053 (school) 
ARPA: RALF@B.GP.CS.CMU.EDU |"Tolerance means excusing the mistakes others make.
FIDO: Ralf Brown at 129/31 | Tact means not noticing them." --Arthur Schnitzler
BITnet: RALF%B.GP.CS.CMU.EDU@CMUCCVMA -=-=- DISCLAIMER? I claimed something?

michel@megamax.UUCP (Michel Rynderman) (03/12/88)

> << rest of stuff gone.

>    	array1 : array[0..maxelts] of record1;

This should be ok if maxelts is defined. However if maxelts is not defined the
compiler may barf.

Michel@megamax

zifrony@TAURUS.BITNET (03/16/88)

I compiled program on an INTEL machine, using the PASCAL-86 compiler, supplied
by INTEL for usage on their development, and cross development systems.
In these programs, I managed to hold a module's global array, which was
larger then 64KB.  These variables are not stored on the stack, but in the
data area, thus, they do not surrender to the stack segment limitations of
64KB alll in all.

mccaugh@uiucdcsb.cs.uiuc.edu (03/18/88)

 Pardon me for saying so, but no one seems to have responded to the original
 question of compiler irregularity, although Ralf (response 2) comes closest.
 Of course this is a compiler error, rendering response 1 superfluous. As to
 the comments about 'maxelts': is this what the compiler refers in its quite
 vague message "Invalid Type"? If not -- and admittedly, nothing else seems
 awry -- it would appear the compiler had not processed the definition of
 type 'record1' first, which specifies the compiler error: failing to process
 definitions in order.
 

milne@ICS.UCI.EDU (Alastair Milne) (03/22/88)

>Of course this is a compiler error, rendering response 1 superfluous. 
>As to the comments about 'maxelts': is this what the compiler refers [to]
>in its quite vague message "Invalid Type"? 

    I don't see how you can conclude so strongly.  It's perfectly reasonable
    for a compiler to refuse to create an object, or the type for an object,
    bigger than it can allocate.  If MaxElts was declared too big, the array
    depending on it could very easily go beyond data segment capacity -- and
    this needn't even presume an 8088/6 machine.

    Also, if MaxElts wasn't declared before that use, the compiler would have
    no way of knowing how big an array to allocate.  Of course, the message
    in  that case should have been 'undeclared identifier', and if this is so,
    the compiler could be taken to task.

    However, although one could ask for a more precise diagnostic, a type
    which can't even create an allocatable object could certainly be
    considered invalid.
    
 
>If not -- and admittedly, nothing else seems
>awry -- it would appear the compiler had not processed the definition of
>type 'record1' first, which specifies the compiler error: failing to process
>definitions in order.

    Until it is determined that there is nothing wrong with MaxElts, whose
    declaration was not in the circulated code fragment, I think this is a
    stab in the dark.  Too great a value for MaxElts is far more likely.


    Alastair Milne