sizeof Ignores Upper Bound of Super Array

Product Version(s): 3.20
Operating System:   MS-DOS
Flags: ENDUSER | TAR17010 buglist3.20 fixlist3.30
Last Modified:  4-OCT-1988    ArticleIdent: Q10410

Problem:

When discussing the sizeof statement, the "Microsoft Pascal Compiler
for the MS-DOS Operating System Reference Manual" states that "if the
variable is a super array, the second form, which gives upper bounds,
must be used."

In the example program below, the second parameter of the sizeof call
is ignored. The upper bound of the allocated pointer is stored in the
second word of the pointer value. When the sizeof function is invoked,
the value stored in the second word of the super array pointer is used
to calculate the size of the super array pointer. However, when the
second parameter is omitted from the sizeof call, PAS1 emits a compile
time error 233 "invalid procedure or function parameter."

The following is the short example code:

   program test(input,output);
   type hundred=lstring(99);
   supar =super array[1..*] of hundred;
   VAR POINTER:^supar;
   Y :word;
   begin
   new(pointer,20);
   Y:=sizeof(pointer^,10);
   writeln('size returned =',y);
   end.

Response:

This behavior has been changed by adding the ability to use the short
form of sizeof on a short array pointer. The long form now returns the
length calculated purely from the values specified in the sizeof call,
and ignores the fields in the pointer. The short form uses only the
pointer fields.

Microsoft has confirmed this to be a problem in Version 3.20. This
problem was corrected in Version 3.30.

Note: a feature, sizeof(p^), has been added where p is a pointer to a
super array. Now, this is a valid expression but it is the
programmer's responsibility to ensure that p^ has been allocated. Also
note that if p = pointer to a one-dimensional super array then
sizeof(p^, 10) depends only on the underlying type of the super array
and 10. Whether or not p^ has been allocated is irrelevant.
