D - varargs with void[]
- "C. Sauls" <ibisbasenji yahoo.com> Mar 28 2004
- "C. Sauls" <ibisbasenji yahoo.com> Mar 28 2004
- Ben Hinkle <bhinkle4 juno.com> Mar 28 2004
- J Anderson <REMOVEanderson badmama.com.au> Mar 28 2004
- "C. Sauls" <ibisbasenji yahoo.com> Mar 29 2004
- J Anderson <REMOVEanderson badmama.com.au> Mar 29 2004
- "C. Sauls" <ibisbasenji yahoo.com> Mar 29 2004
I remember vaguely Walter mentioning the use of void[] in D to
facilitate the same ability as void* in C... could a little syntax sugar
be devised to support variable parameter lists using void[]? Maybe
something like:
void myprintf(char[] format, void[][] data) {
int idx;
char fc;
char[] out;
// ...
switch (fc) {
case 'd':
out ~= .toString(cast(int) data[idx++]);
break;
// ...
case 's':
out ~= .toString(cast(char[]) data[idx++]);
break;
// ...
}
// ...
}
Just a thought.
-C. Sauls
-Invironz
Mar 28 2004
Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Just to see if this would technically work at all, I tossed together this little experiment, with (IMHO) pretty good results. Please excuse the extrememly rudimentary print() function. :) [Source code attached] -C. Sauls -Invironz
Mar 28 2004
On Sun, 28 Mar 2004 20:24:25 -0600, "C. Sauls" <ibisbasenji yahoo.com> wrote:Just to see if this would technically work at all, I tossed together this little experiment, with (IMHO) pretty good results. Please excuse the extrememly rudimentary print() function. :)
I think that code will only work for data that fits inside (void[]).sizeof bytes. Since "int" and "char[]" fit it works but with a big struct it wouldn't. For anything bigger it would be taking a (void[]).sizeof chunk out of the data and passing that around. Remember dynamic arrays consist of a length int followed by a pointer to the data (in this case that pointer has type void*).[Source code attached] -C. Sauls -Invironz
Mar 28 2004
Ben Hinkle wrote:On Sun, 28 Mar 2004 20:24:25 -0600, "C. Sauls" <ibisbasenji yahoo.com> wrote:Just to see if this would technically work at all, I tossed together this little experiment, with (IMHO) pretty good results. Please excuse the extrememly rudimentary print() function. :)
I think that code will only work for data that fits inside (void[]).sizeof bytes. Since "int" and "char[]" fit it works but with a big struct it wouldn't. For anything bigger it would be taking a (void[]).sizeof chunk out of the data and passing that around. Remember dynamic arrays consist of a length int followed by a pointer to the data (in this case that pointer has type void*).
-- -Anderson: http://badmama.com.au/~anderson/
Mar 28 2004
If you mean to make data of type void*[] instead of void[][] that won't work... I tried it. Cannot (apparently) cast a char[] or a struct to void*, but can cast anything to void[] (with varying degrees of success). -C. Sauls -Invironz J Anderson wrote:Ben Hinkle wrote:On Sun, 28 Mar 2004 20:24:25 -0600, "C. Sauls" <ibisbasenji yahoo.com> wrote:Just to see if this would technically work at all, I tossed together this little experiment, with (IMHO) pretty good results. Please excuse the extrememly rudimentary print() function. :)
I think that code will only work for data that fits inside (void[]).sizeof bytes. Since "int" and "char[]" fit it works but with a big struct it wouldn't. For anything bigger it would be taking a (void[]).sizeof chunk out of the data and passing that around. Remember dynamic arrays consist of a length int followed by a pointer to the data (in this case that pointer has type void*).
Mar 29 2004
C. Sauls wrote:If you mean to make data of type void*[] instead of void[][] that won't work... I tried it. Cannot (apparently) cast a char[] or a struct to void*, but can cast anything to void[] (with varying degrees of success). -C. Sauls -Invironz
What about? char [] string; void *tt = (void*)&string[0]; //Looses length void *t = (void*)string; struct a { } a A; void *t = (void*)&A; What do you mean?J Anderson wrote:Ben Hinkle wrote:On Sun, 28 Mar 2004 20:24:25 -0600, "C. Sauls" <ibisbasenji yahoo.com> wrote:Just to see if this would technically work at all, I tossed together this little experiment, with (IMHO) pretty good results. Please excuse the extrememly rudimentary print() function. :)
I think that code will only work for data that fits inside (void[]).sizeof bytes. Since "int" and "char[]" fit it works but with a big struct it wouldn't. For anything bigger it would be taking a (void[]).sizeof chunk out of the data and passing that around. Remember dynamic arrays consist of a length int followed by a pointer to the data (in this case that pointer has type void*).
-- -Anderson: http://badmama.com.au/~anderson/
Mar 29 2004
Just tried rigging up a struct with two int fields and a char[] field. The ints work jut fine, the char[] is lost, so you have a point. -C. Sauls -Invironz Ben Hinkle wrote:On Sun, 28 Mar 2004 20:24:25 -0600, "C. Sauls" <ibisbasenji yahoo.com> wrote:Just to see if this would technically work at all, I tossed together this little experiment, with (IMHO) pretty good results. Please excuse the extrememly rudimentary print() function. :)
I think that code will only work for data that fits inside (void[]).sizeof bytes. Since "int" and "char[]" fit it works but with a big struct it wouldn't. For anything bigger it would be taking a (void[]).sizeof chunk out of the data and passing that around. Remember dynamic arrays consist of a length int followed by a pointer to the data (in this case that pointer has type void*).[Source code attached] -C. Sauls -Invironz
Mar 29 2004









J Anderson <REMOVEanderson badmama.com.au> 