digitalmars.D - Array to variadic function?
- bobef (16/16) Nov 28 2005 Is there some way to pass something like array to variadic function. I
- pragma (4/20) Nov 28 2005 I'm shooting from the hip here, but have you tried this?
- bobef (3/32) Dec 01 2005 I can't. I am not allowed to change any of the two functions. The one is...
- Walter Bright (4/20) Dec 01 2005 Redeclare someCfunction as:
- Ivan Senji (6/35) Dec 01 2005 I think the problem is you can't allways redeclare a function.
- bobef (13/43) Dec 02 2005 extern(C) void someCfunction(int[] a...)
Is there some way to pass something like array to variadic function. I mean often there is no variant where function take valist instead of ... and when you need to wrap this function what do you do? Write many ifs? I will illustrate my question with example void someCfunction(int a,...) { ... do stuff here } void dmdscript_for_example_function(/*all_the_stuff*/,Value[] values) { if(values.length==1) someCfunction(345,values[0].toString()); else if(values.length==2) someCfunction(543,values[0].toString(),values[1].toString()); //etc... } There must be a better way to do this...
Nov 28 2005
In article <dmfcgr$2hpa$1 digitaldaemon.com>, bobef says...Is there some way to pass something like array to variadic function. I mean often there is no variant where function take valist instead of ... and when you need to wrap this function what do you do? Write many ifs? I will illustrate my question with example void someCfunction(int a,...) { ... do stuff here } void dmdscript_for_example_function(/*all_the_stuff*/,Value[] values) { if(values.length==1) someCfunction(345,values[0].toString()); else if(values.length==2) someCfunction(543,values[0].toString(),values[1].toString()); //etc... } There must be a better way to do this...I'm shooting from the hip here, but have you tried this? void foobar(int a,void*[]...){ /* stuff */ } - EricAnderton at yahoo
Nov 28 2005
pragma wrote:In article <dmfcgr$2hpa$1 digitaldaemon.com>, bobef says...I can't. I am not allowed to change any of the two functions. The one is defined by dmdscript and the other by the (guy_who_wrote_it !is me)Is there some way to pass something like array to variadic function. I mean often there is no variant where function take valist instead of ... and when you need to wrap this function what do you do? Write many ifs? I will illustrate my question with example void someCfunction(int a,...) { ... do stuff here } void dmdscript_for_example_function(/*all_the_stuff*/,Value[] values) { if(values.length==1) someCfunction(345,values[0].toString()); else if(values.length==2) someCfunction(543,values[0].toString(),values[1].toString()); //etc... } There must be a better way to do this...I'm shooting from the hip here, but have you tried this? void foobar(int a,void*[]...){ /* stuff */ } - EricAnderton at yahoo
Dec 01 2005
"bobef" <bobef lessequal.com> wrote in message news:dmfcgr$2hpa$1 digitaldaemon.com...Is there some way to pass something like array to variadic function. I mean often there is no variant where function take valist instead of ... and when you need to wrap this function what do you do? Write many ifs? I will illustrate my question with example void someCfunction(int a,...) { ... do stuff here } void dmdscript_for_example_function(/*all_the_stuff*/,Value[] values) { if(values.length==1) someCfunction(345,values[0].toString()); else if(values.length==2) someCfunction(543,values[0].toString(),values[1].toString()); //etc... } There must be a better way to do this...Redeclare someCfunction as: void someCfunction(int[] a ...)
Dec 01 2005
Walter Bright wrote:"bobef" <bobef lessequal.com> wrote in message news:dmfcgr$2hpa$1 digitaldaemon.com...I think the problem is you can't allways redeclare a function. What would be nice is to be able to construct arguments and pass them to another function. For example to be able to (with ...) take n arguments, and pass to another variadic function some of them, for example a slice.Is there some way to pass something like array to variadic function. I mean often there is no variant where function take valist instead of ... and when you need to wrap this function what do you do? Write many ifs? I will illustrate my question with example void someCfunction(int a,...) { ... do stuff here } void dmdscript_for_example_function(/*all_the_stuff*/,Value[] values) { if(values.length==1) someCfunction(345,values[0].toString()); else if(values.length==2) someCfunction(543,values[0].toString(),values[1].toString()); //etc... } There must be a better way to do this...Redeclare someCfunction as: void someCfunction(int[] a ...)
Dec 01 2005
Walter Bright wrote:"bobef" <bobef lessequal.com> wrote in message news:dmfcgr$2hpa$1 digitaldaemon.com...extern(C) void someCfunction(int[] a...) { printf("as %d %d\0",a); } int main(char[][] argv) { int[] a; a~=5;a~=6; someCfunction(a); return 1; } outputs "as 2 9243472"Is there some way to pass something like array to variadic function. I mean often there is no variant where function take valist instead of ... and when you need to wrap this function what do you do? Write many ifs? I will illustrate my question with example void someCfunction(int a,...) { ... do stuff here } void dmdscript_for_example_function(/*all_the_stuff*/,Value[] values) { if(values.length==1) someCfunction(345,values[0].toString()); else if(values.length==2) someCfunction(543,values[0].toString(),values[1].toString()); //etc... } There must be a better way to do this...Redeclare someCfunction as: void someCfunction(int[] a ...)
Dec 02 2005
In article <dmpvro$2b3f$1 digitaldaemon.com>, bobef says...Walter Bright wrote:Try this:"bobef" <bobef lessequal.com> wrote in message news:dmfcgr$2hpa$1 digitaldaemon.com...extern(C) void someCfunction(int[] a...) { printf("as %d %d\0",a); } int main(char[][] argv) { int[] a; a~=5;a~=6; someCfunction(a); return 1; } outputs "as 2 9243472"Is there some way to pass something like array to variadic function. I mean often there is no variant where function take valist instead of ... and when you need to wrap this function what do you do? Write many ifs? I will illustrate my question with example void someCfunction(int a,...) { ... do stuff here } void dmdscript_for_example_function(/*all_the_stuff*/,Value[] values) { if(values.length==1) someCfunction(345,values[0].toString()); else if(values.length==2) someCfunction(543,values[0].toString(),values[1].toString()); //etc... } There must be a better way to do this...Redeclare someCfunction as: void someCfunction(int[] a ...)extern(C) void someCfunction(int[] a...) { writefln("as %s",a); }- EricAnderton at yahoo
Dec 02 2005
pragma wrote:I got confused....... This is the real code I am asking the question for. There is no xchat_emit_writefln... And xchat_emit_print is what I meant with someCfunction... //this is part of struct actually extern(C) int (*xchat_emit_print) (xchat_plugin *ph,char *event_name, ...); void* g_xchat_emit_print(Dobject pthis,CallContext* cc,Dobject othis,Value* ret,Value[] arglist) { //todo: the whole arglist should be passed to the variadic function Value *v=getErrorReturn(arglist,1,"xchat_emit_print"); if(!v) { if(arglist.length==1) this_ph.xchat_emit_print(this_ph,toStringz(arglist[0].toString())); else if(arglist.length==2) this_ph.xchat_emit_print(this_ph,toStringz(arglist[0].toString()),toStringz(arglist[1].toString())); //............ }outputs "as 2 9243472"Try this:extern(C) void someCfunction(int[] a...) { writefln("as %s",a); }- EricAnderton at yahoo
Dec 03 2005