Prof Abimbola Olowofoyeku wrote:
On 13 Oct 01, at 18:00, CBFalconer wrote:
[...]
I am new here, but an old hand at Pascal and Pascal implementation.
Will somebody please explain why this 'const' extension exists at all? A non VAR parameter is always passed by value, so the original cannot be modified. Thus I see absolutely no purpose to it.
There is a point. 'const' parameters are a Borland extension that allows you to pass a parameter by reference, but in a read only format. It can help with stack overflows, performance, etc. GPC has had some issues with const parameters in the past, and I am sure that they are not all sorted out yet. This may be one of them.
I see. Seems like the wrong way, to me. One more Borland attempt to C-ify the language.
My approach (I think) would be to check the usage within the function block, and if not modified and the size is above the size of a pointer, convert the usage to a VAR. This could be done without fixups if the normal access to a large parameter was via a local (and programmer invisible) pointer. Except that that won't work unless the practice for large parameters is to copy them into local storage, rather than have the caller copy them onto the stack. This in turn means conformant arrays have to be VAR (which I vaguely recall is already the specification) unless there is some sort of alloca equivalent available internally. It all messes up the function entry code.