D - Using variable argument lists in D
- Pasi Hirvonen (11/11) Apr 22 2004 Hello.
- C. Sauls (8/23) Apr 22 2004 As far as I know, va_list is the way to do it (complete with func(...)
- Achilleas Margaritis (20/46) Apr 22 2004 I think the best way for D argument lists is with a variant type: all ar...
Hello. First of all, please smack me and direct me to the correct page if the reference documentation actually covers this and I missed it. What is the proper way to handle variable argument lists in D? Phobos' std stuff seems to use va_list stuff but guessing the Right Way is bit annoying. I probably want to call C functions such as vfprintf() when using them too, but I doubt that that it's going to be a problem. Thanks in advance
Apr 22 2004
As far as I know, va_list is the way to do it (complete with func(...) syntax). There are a few experimental systems out there using templates, but I haven't personally played with any of them. Of course if all your arguments are of the same type, you could use an array... (Which will be much more usable once array literals are implemented.) -C. Sauls -Invironz Pasi Hirvonen wrote:Hello. First of all, please smack me and direct me to the correct page if the reference documentation actually covers this and I missed it. What is the proper way to handle variable argument lists in D? Phobos' std stuff seems to use va_list stuff but guessing the Right Way is bit annoying. I probably want to call C functions such as vfprintf() when using them too, but I doubt that that it's going to be a problem. Thanks in advance
Apr 22 2004
C. Sauls wrote:As far as I know, va_list is the way to do it (complete with func(...) syntax). There are a few experimental systems out there using templates, but I haven't personally played with any of them. Of course if all your arguments are of the same type, you could use an array... (Which will be much more usable once array literals are implemented.) -C. Sauls -Invironz Pasi Hirvonen wrote:I think the best way for D argument lists is with a variant type: all arguments passed where va arguments are expected are promoted to type 'variant' and then by the use of RTTI one can ask what the type of the variant is and act accordingly. The va_list could be presented as an array of variants which is a static property of the function. Example: void printf(char[] format, ...) { for(int i = 0; i < printf.args.size; i++) { switch (printf.args[i].type) { case int.type: break; case char[].type: break; } } }Hello. First of all, please smack me and direct me to the correct page if the reference documentation actually covers this and I missed it. What is the proper way to handle variable argument lists in D? Phobos' std stuff seems to use va_list stuff but guessing the Right Way is bit annoying. I probably want to call C functions such as vfprintf() when using them too, but I doubt that that it's going to be a problem. Thanks in advance
Apr 22 2004