<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Ryan Joseph via fpc-devel <<a href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>> schrieb am Di., 10. Dez. 2019, 22:29:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
> On Dec 10, 2019, at 11:38 AM, Sven Barth via fpc-devel <<a href="mailto:fpc-devel@lists.freepascal.org" target="_blank" rel="noreferrer">fpc-devel@lists.freepascal.org</a>> wrote:<br>
> <br>
> First of Object Pascal supports "array of const" which is safer due to a added type field for each entry. <br>
> <br>
<br>
>From the users standpoint only real difference is the [] syntax and if the array of const is the last (or only) parameter the compiler could infer it right? i.e.<br>
<br>
DoThis(firstParam, [1,2,3]);<br>
<br>
doesn't really need the [] in this case since the last parameters would have to be an array of const.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">From the view of the *caller* you are mostly right. Though the square brackets can't be left away, cause we're talking about an array parameter here. If it would be allowed for array of const then it would also need to be allowed for other open array parameters for consistency. But then it wouldn't be consistent with open array arguments in the middle. Each exception makes the language more complex.</div><div dir="auto">Fun fact: There is in fact one such case for open arrays: a single element may be passed without the square brackets. </div><div dir="auto"><br></div><div dir="auto">Also a further difference is that "array of const" does not need to be the last parameter and you can have multiple such parameters in the same call. And it can be used with any calling convention. </div><div dir="auto"><br></div><div dir="auto">Please note that it is possible in FPC to declare an external, variadic function with an "array of const" parameter instead of varargs. The call then looks like a normal "array of const" call in Object Pascal, but internally the arguments are passed using the variadic ABI. </div><div dir="auto"><br></div><div dir="auto">For the *callee* things are vastly different however. With "array of const" you can determine both the amount of arguments as well as the type of each. In variadic functions that either needs to be fix inside the function (e.g. the optional mode parameter of the Posix open() function) or it needs some kind of schematic (the format string in printf/scanf) to determine the argument types. </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>