Optional parameters referring to previous parameters?
Tove
tove at fransson.se
Thu May 10 10:48:36 PDT 2012
On Thursday, 10 May 2012 at 17:41:23 UTC, dennis luehring wrote:
> Am 10.05.2012 19:07, schrieb Tove:
>> auto my_extended_alloca(size_t size, void* buf=alloca(size))
>> {
>> return buf;
>> }
>
> and whats the difference to?
>
> auto my_extended_alloca(size_t size, void* buf)
> {
> return alloca(size);
> }
>
> except that you hide the alloca in the interface
> which can be easily overwritten with malloc or something?
>
> auto x = my_extended_alloca( 10, malloc(100) ); ???
When used in the parameter list, the alloca() is injected into
the parent scope.
Your version doesn't work at all, as the allocation automatically
ends with the scope of my_extended_alloca() instead of the scope
of the caller!
More information about the Digitalmars-d
mailing list