 |
 |
|
 |
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Is it possible to create a macro with a variable number of
parameters?
I'm trying to create a macro that counts the number of
parameters passed to it and then issue the #macro definition.
Is this possible?
I want a way to make it so the user doesn't have to provide
information that isn't necessary. Based on the value of the
first parameter, the second is always needed, but the third
may not be. I'd like to allow the user to do the following.
myMacro(0,"a")
or
myMacro(1,"a","b")
The first and second parameter are needed, but if the first is a 0
(instead of a 1) the third value isn't necessary.
Anyone have any ideas?
--
============================================================
Suburbia is where the developer bulldozes out the trees,
then names the streets after them.
-- Bill Vaughn
============================================================
Friday, June 18, 1999 - 02:06 PM (EDT)
============================================================
_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~~~~~~~~~~-_
+ + +
+ Chris C. Conner + This +
+ cco### [at] amerisure com-NOSPAM + space +
+ con### [at] geocities com-NOSPAM + for +
+ con### [at] usa net-NOSPAM + rent +
+ + +
~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-__________-~
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: Margus Ramst
Subject: Re: Macro with variable number of parameters...
Date: 18 Jun 1999 15:33:19
Message: <376a9eff@news.povray.org>
|
|
 |
|  |
|  |
|
 |
I'd say it's not possible. Aside from the fact that a called #macro always
expects the same number of params specified in the original, there is a
problem of ambiquity. Let's say, out of 5 parameters the 3rd isn't
necessary. How would you go about omitting it?
The best I've managed was to have long parameters (strings or vectors) take
the value 0 as an alternative meaning "do not use". This, of course, is not
always applicable for vectors. Another thing is to make it possible to use,
for example, "3" instead of "<3,3,3>" by manually promoting the float to a
vector (#local Vector=Float+<0,0,0>;)
But what you want, I think is impossible.
Margus
con### [at] geocities com wrote in message
<376a8bf8$1$pbaarep$mr2ice@news.povray.org>...
>Is it possible to create a macro with a variable number of
>parameters?
>
>
>I'm trying to create a macro that counts the number of
>parameters passed to it and then issue the #macro definition.
>
>Is this possible?
>
>I want a way to make it so the user doesn't have to provide
>information that isn't necessary. Based on the value of the
>first parameter, the second is always needed, but the third
>may not be. I'd like to allow the user to do the following.
>
>myMacro(0,"a")
>
>or
>
>myMacro(1,"a","b")
>
>The first and second parameter are needed, but if the first is a 0
>(instead of a 1) the third value isn't necessary.
>
>Anyone have any ideas?
>
>--
>============================================================
> Suburbia is where the developer bulldozes out the trees,
> then names the streets after them.
>
> -- Bill Vaughn
>============================================================
> Friday, June 18, 1999 - 02:06 PM (EDT)
>============================================================
>
>_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~~~~~~~~~~-_
>+ + +
>+ Chris C. Conner + This +
>+ cco### [at] amerisure com-NOSPAM + space +
>+ con### [at] geocities com-NOSPAM + for +
>+ con### [at] usa net-NOSPAM + rent +
>+ + +
>~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-__________-~
>
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On Fri, 18 Jun 1999 14:06:39 -0400, con### [at] geocities com wrote:
>Is it possible to create a macro with a variable number of
>parameters?
>
>
>I'm trying to create a macro that counts the number of
>parameters passed to it and then issue the #macro definition.
>
>Is this possible?
Is it possible to pass an array? If yes then that's one possible way
round it.
Cheers,
Cliff Bowman
Why not pay my 3D Dr Who site a visit at
http://www.geocities.com/Area51/Dimension/7855/
PS change ".duffnet" to ".net" if replying via e-mail
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: Nieminen Mika
Subject: Re: Macro with variable number of parameters...
Date: 19 Jun 1999 11:15:34
Message: <376bb416@news.povray.org>
|
|
 |
|  |
|  |
|
 |
In povray.general con### [at] geocities com wrote:
: myMacro(0,"a")
: or
: myMacro(1,"a","b")
#macro myMacro(itemsAmount, stringArray)
...
#end
--
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 19 Jun 1999 11:15:34 -0400, Nieminen Mika <war### [at] cc tut fi> wrote:
>In povray.general con### [at] geocities com wrote:
>: myMacro(0,"a")
>
>: or
>
>: myMacro(1,"a","b")
>
>#macro myMacro(itemsAmount, stringArray)
> ...
>#end
Or just pass the array and use dimension_size.
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: Matthias
Subject: Re: Macro with variable number of parameters...
Date: 21 Jun 1999 11:21:08
Message: <376e5864@news.povray.org>
|
|
 |
|  |
|  |
|
 |
Ron Parker <par### [at] fwi com> schrieb in im Newsbeitrag:
376dcac4.120103227@news.povray.org...
> On 19 Jun 1999 11:15:34 -0400, Nieminen Mika <war### [at] cc tut fi> wrote:
>
> >In povray.general con### [at] geocities com wrote:
> >: myMacro(0,"a")
> >
> >: or
> >
> >: myMacro(1,"a","b")
> >
> >#macro myMacro(itemsAmount, stringArray)
> > ...
> >#end
>
> Or just pass the array and use dimension_size.
>
I´ve been using this technique in on eof my projects but the it has one
disadvantage when declaring an array you´ll have to tell POV the number of
elements used in it (which makes the same as just typing an unused
parameter.
My idea is to use a macro with two Parameters. the first is a usual float.
the second could be a float or a vector; like this
#macro(bool,data)
#if bool
#declare u.data = a;
#declare v.data =b;
#else
#declare data = a;
#end
#end
this of course assumes that the user enters the maco correctly (using only
two parameters if bool = 1 )
hope Icould help you
maesju **
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: Rainer Mager
Subject: Re: Macro with variable number of parameters...
Date: 21 Jun 1999 21:36:14
Message: <376ee88e@news.povray.org>
|
|
 |
|  |
|  |
|
 |
This probably isn't ideal but how about...
#macro myMacro2( val1, val2 )
myRealMacro( val1, val2, "" )
#end
#macro myMacro3( val1, val2, val3 )
myRealMacro( val1, val2, val3 )
#end
#macro myRealMacro( val1, val2, val3 )
...
#end
...and use they both as...
myMacro2( val1, val2 )
myMacro3( val1, val2, val3 )
--Rainer
<con### [at] geocities com> wrote in message
news:376a8bf8$1$pbaarep$mr2ice@news.povray.org...
> Is it possible to create a macro with a variable number of
> parameters?
>
>
> I'm trying to create a macro that counts the number of
> parameters passed to it and then issue the #macro definition.
>
> Is this possible?
>
> I want a way to make it so the user doesn't have to provide
> information that isn't necessary. Based on the value of the
> first parameter, the second is always needed, but the third
> may not be. I'd like to allow the user to do the following.
>
> myMacro(0,"a")
>
> or
>
> myMacro(1,"a","b")
>
> The first and second parameter are needed, but if the first is a 0
> (instead of a 1) the third value isn't necessary.
>
> Anyone have any ideas?
>
> --
> ============================================================
> Suburbia is where the developer bulldozes out the trees,
> then names the streets after them.
>
> -- Bill Vaughn
> ============================================================
> Friday, June 18, 1999 - 02:06 PM (EDT)
> ============================================================
>
> _-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~~~~~~~~~~-_
> + + +
> + Chris C. Conner + This +
> + cco### [at] amerisure com-NOSPAM + space +
> + con### [at] geocities com-NOSPAM + for +
> + con### [at] usa net-NOSPAM + rent +
> + + +
> ~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-__________-~
>
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
> Is it possible to create a macro with a variable number of
> parameters?
>
> I'm trying to create a macro that counts the number of
> parameters passed to it and then issue the #macro definition.
>
> Is this possible?
>
> I want a way to make it so the user doesn't have to provide
> information that isn't necessary. Based on the value of the
> first parameter, the second is always needed, but the third
> may not be. I'd like to allow the user to do the following.
>
> myMacro(0,"a")
>
> or
>
> myMacro(1,"a","b")
>
> The first and second parameter are needed, but if the first is a 0
> (instead of a 1) the third value isn't necessary.
>
> Anyone have any ideas?
IF it is possible, it remains poor programming practice. Either
the first parameter is the number of additional parameters to be
passed or write two macros. Your examples would then pass (1,"a")
and (2,"a","b") Alternatively the passing routine can pass an end
of list marker.
It is also a dangerous language that would permit what you want.
FORTH comes to mind.
--
<blink>-------please--don't-----------------</blink>
http://www.giwersworld.org/artii/
http://www.giwersworld.org/artiii/
Finally up on 99/06/22 updated 06/30
Post a reply to this message
Attachments:
Download 'us-ascii' (1 KB)
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On Sun, 04 Jul 1999 17:17:33 -0400, Matt Giwer
<mgi### [at] giwersworld org> wrote:
> It is also a dangerous language that would permit what you want.
>FORTH comes to mind.
C and C++ come to mind too. I couldn't live without varargs.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Ron Parker wrote:
> On Sun, 04 Jul 1999 17:17:33 -0400, Matt Giwer
> <mgi### [at] giwersworld org> wrote:
>
> > It is also a dangerous language that would permit what you want.
> >FORTH comes to mind.
>
> C and C++ come to mind too. I couldn't live without varargs.
No no no no no no.......... Argh................
So, does your code have lots of GOTO's also? Functions named things like
"function1()" and "func2()"? Void pointers cast all over the place? ;-)
I never got into FORTH much, but I agree that C and C++ are very dangerous.
That's why I'm glad basic programming courses are switching over to Java.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On Sun, 04 Jul 1999 16:09:31 -0700, "Jon A. Cruz"
<jon### [at] geocities com> wrote:
>Ron Parker wrote:
>
>> On Sun, 04 Jul 1999 17:17:33 -0400, Matt Giwer
>> <mgi### [at] giwersworld org> wrote:
>>
>> > It is also a dangerous language that would permit what you want.
>> >FORTH comes to mind.
>>
>> C and C++ come to mind too. I couldn't live without varargs.
>So, does your code have lots of GOTO's also? Functions named things like
>"function1()" and "func2()"? Void pointers cast all over the place? ;-)
Nah. But varargs is a thing that can't be done any other way. I have
this function called ODS that takes printf-style arguments, sprintf's
into a buffer, and calls OutputDebugString. I don't know of any other
sane way to do that. Streams are not considered sane, BTW.
Well... actually... now you mention it, I do have lots of void
pointers too. Object-oriented programming has a purpose, but when it
gets in the way, I find a different tool.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Ron Parker wrote:
> On Sun, 04 Jul 1999 16:09:31 -0700, "Jon A. Cruz"
> <jon### [at] geocities com> wrote:
>
> >Ron Parker wrote:
> >
> >> On Sun, 04 Jul 1999 17:17:33 -0400, Matt Giwer
> >> <mgi### [at] giwersworld org> wrote:
> >>
> >> > It is also a dangerous language that would permit what you want.
> >> >FORTH comes to mind.
> >>
> >> C and C++ come to mind too. I couldn't live without varargs.
>
> >So, does your code have lots of GOTO's also? Functions named things like
> >"function1()" and "func2()"? Void pointers cast all over the place? ;-)
>
> Nah. But varargs is a thing that can't be done any other way. I have
> this function called ODS that takes printf-style arguments, sprintf's
> into a buffer, and calls OutputDebugString. I don't know of any other
> sane way to do that. Streams are not considered sane, BTW.
>
> Well... actually... now you mention it, I do have lots of void
> pointers too. Object-oriented programming has a purpose, but when it
> gets in the way, I find a different tool.
Ewwww! void pointers are Evil.
Of course, when programming for Windows, I am often forced to use them. :-(
Let's try not to corrupt those poor, impressionable programmers out there.
Oh. That brings things back on topic. :-) It could be used for things, but
then again there is great danger, so it's probably best to keep it out.
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: Nieminen Mika
Subject: Re: Macro with variable number of parameters...
Date: 5 Jul 1999 02:16:17
Message: <37804db1@news.povray.org>
|
|
 |
|  |
|  |
|
 |
In povray.general Ron Parker <par### [at] fwi com> wrote:
: Nah. But varargs is a thing that can't be done any other way. I have
: this function called ODS that takes printf-style arguments, sprintf's
: into a buffer, and calls OutputDebugString. I don't know of any other
: sane way to do that. Streams are not considered sane, BTW.
sprintf is evil (unless you know exactly the size of the output).
--
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Nieminen Mika wrote:
>
> sprintf is evil (unless you know exactly the size of the output).
but snprintf is not.
dik
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: Nieminen Mika
Subject: Re: Macro with variable number of parameters...
Date: 6 Jul 1999 09:37:24
Message: <37820694@news.povray.org>
|
|
 |
|  |
|  |
|
 |
In povray.general Dick Balaska <dic### [at] buckosoft com> wrote:
: but snprintf is not.
snprintf is not a standard function.
--
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Nieminen Mika wrote:
>
> In povray.general Dick Balaska <dic### [at] buckosoft com> wrote:
> : but snprintf is not.
>
> snprintf is not a standard function.
I use it on all the time on code that compiles with VC++, gcc, and c89.
That's standard enough for me.
dik
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: Nieminen Mika
Subject: Re: Macro with variable number of parameters...
Date: 8 Jul 1999 01:27:29
Message: <378436c1@news.povray.org>
|
|
 |
|  |
|  |
|
 |
In povray.general Dick Balaska <dic### [at] buckosoft com> wrote:
: I use it on all the time on code that compiles with VC++, gcc, and c89.
: That's standard enough for me.
Well, as long as you don't compile it in a SunOS or Digital Unix or other
OS's...
--
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Nieminen Mika wrote:
>
> In povray.general Dick Balaska <dic### [at] buckosoft com> wrote:
> : I use it on all the time on code that compiles with VC++, gcc, and c89.
> : That's standard enough for me.
>
> Well, as long as you don't compile it in a SunOS or Digital Unix or other
> OS's...
...with a compiler that is more than 3 years old.
Linux, *BSD, Solaris, SunOS 4.1.[34] = gcc
Dec Unix (Alpha), HP-UX 9-10, SCO = c89
Win9[58], NT4 = VC++
The snprintf, vsnprintf, etc functions are years old and are there to help prevent
the exploitable buffer overruns so common in bad code. All good daemons should
be using them.
c89 comes from the loins of Digital Unix.
Sun has been trying to kill SunOS for almost 10 years, so i don't expect
it's native compiler to be very up to date. I switched to gcc on SunOS 7 or 8 years
ago because its compiler (cc?) was very buggy and unsupported.
dik
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: Nieminen Mika
Subject: Re: Macro with variable number of parameters...
Date: 9 Jul 1999 02:06:13
Message: <37859155@news.povray.org>
|
|
 |
|  |
|  |
|
 |
In povray.general Dick Balaska <dic### [at] buckosoft com> wrote:
: The snprintf, vsnprintf, etc functions are years old and are there to help prevent
: the exploitable buffer overruns so common in bad code. All good daemons should
: be using them.
Perhaps they should, but they don't have to. snprintf is not part of the
ANSI C standard. If you use non-standard functions, you will be making
non-portable code.
pohjanrastas:~>cat test.c
#include <stdio.h>
int main(void)
{ char test[10];
snprintf(test, 10, "%i", 2);
printf("%s\n", test);
return 0;
}
pohjanrastas:~>uname -a
SunOS pohjanrastas 5.5.1 Generic_103640-27 sun4m sparc SUNW,SPARCstation-4
pohjanrastas:~>gcc -Wall test.c
test.c: In function `main':
test.c:5: warning: implicit declaration of function `snprintf'
/var/tmp/cc6HtB7O.o: In function `main':
/var/tmp/cc6HtB7O.o(.text+0x1c): undefined reference to `snprintf'
collect2: ld returned 1 exit status
pohjanrastas:~>
assari:~>uname -a
OSF1 assari V4.0 1091 alpha
assari:~>gcc -Wall test.c
test.c: In function `main':
test.c:5: warning: implicit declaration of function `snprintf'
/bin/ld:
Unresolved:
snprintf
collect2: ld returned 1 exit status
assari:~>
--
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|
 |