[fpc-pascal] dereferenced pointer as open array argument

Seth Grover sethdgrover at gmail.com
Fri Sep 18 16:40:17 CEST 2015


Imagine I have this function:

procedure ArrayTest(const data : array of char);
begin
  ...
end;

and in another routine I have a pchar variable. If I slice the array byte
doing this:

ArrayTest(myPChar[0..99]);

then inside ArrayTest it will appear that data is 100 characters, which is
exactly what I'd expect.

However, it surprised me that this syntax was accepted (with a dereferenced
pchar):

ArrayTest(myPChar^);

as well as this syntax (with a simple char):

ArrayTest(myChar);

In both of those cases, ArrayTest thinks it's got an array of length 1.

My question is (and I know this is a long shot): is there some sort of
compiler directive or directive I can include in my source code to disallow
the syntax of my second and third examples, ie., to disallow passing a
single element as an open array?

Thanks,

-SG
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20150918/5b9f0e5b/attachment.html>


More information about the fpc-pascal mailing list