www.digitalmars.com         C & C++   DMDScript  

D - what about vaarg and default parameters?

reply bobef <bobef_member pathlink.com> writes:
i couldn't find anything about variable arguments ( int f(int x,...) )
and default parameters ( int func(int x=0) ) in the documentation...
anyone knows about this?
Apr 24 2004
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
bobef wrote:

i couldn't find anything about variable arguments ( int f(int x,...) )
  
Same as C.
and default parameters ( int func(int x=0) ) in the documentation...
anyone knows about this?
Not supported (I wish it was). -- -Anderson: http://badmama.com.au/~anderson/
Apr 24 2004
next sibling parent reply renZYX hotmail.com writes:
In article <c6d6n9$1n5v$1 digitaldaemon.com>, J Anderson says...
bobef wrote:

i couldn't find anything about variable arguments ( int f(int x,...) )
  
Same as C.
Does this means that D is also vulnerable to the 'format string exploit'? Or is-it catched by the array bound checking? What happens if someone do: printf("%s"); ? Best regards.
and default parameters ( int func(int x=0) ) in the documentation...
anyone knows about this?
Not supported (I wish it was). -- -Anderson: http://badmama.com.au/~anderson/
RenoX
Apr 24 2004
parent Ilya Minkov <minkov cs.tum.edu> writes:
renZYX hotmail.com schrieb:
 Does this means that D is also vulnerable to the 'format string exploit'?
 Or is-it catched by the array bound checking?
 
 What happens if someone do: printf("%s"); ?
Exactly what you expect in C. That's one of the many reasons why you better not use varargs until we have better ones. -eye
Apr 24 2004
prev sibling parent "Unknown W. Brackets" <unknown at.simplemachines.dot.org> writes:
J Anderson wrote:
 bobef wrote:
 and default parameters ( int func(int x=0) ) in the documentation...
 anyone knows about this?
Not supported (I wish it was).
In my very humble opinion, *one* of these solutions should be available. Whether they are going to be inlined or not, having to make a dozen function definitions to "redirect" to other functions is a pain, and the way I program I use defaulting whenever possible. As an example, PHP is rather good support for this - and many of the built in functions for it, as well as custom ones, have benefitted greatly. Perhaps the biggest advantage is: Old function: void doSomethingWith(int i); New function: void doSomethingWith(int i, bool specialCoolNewFlag = false); In other words, it allows extension of pre-existing functions without losing the functionality. PHP has done this with functions such as print_r. (print readable, meaning format any variable in a very readable format, extremely useful for debugging.) In PHP 4.3.0, they added a flag "return" to it so you could chose to have the output RETURNED instead of outputted by the previously void function. Right now you'd have to overload it with a quick function that just calls the non-overloaded version. And ugly way to get around the issue... Defaulting is also useful when you have a parameter that is an array, and could be "none". It is logical to simply omit this parameter, instead of providing an empty array... The entire Zend (PHP) API uses, basically, variable functions - meaning every PHP function that is written in C uses an array to store it's passed parameter list. But, it's an array of zval objects, which are basically variants - not really a built in thing. This is why I think support for defaulted parameters would be terribly useful, and make variable argument lists (which are difficult to well implement..) unneccessary in most cases. -[Unknown]
Apr 24 2004