POV-Ray : Newsgroups : povray.programming : Macro with variable number of parameters... Server Time
20 Dec 2025 20:26:01 EST (-0500)
  Macro with variable number of parameters... (Message 8 to 17 of 17)  
<<< Previous 7 Messages Goto Initial 10 Messages
From: Matt Giwer
Subject: Re: Macro with variable number of parameters...
Date: 4 Jul 1999 17:17:03
Message: <377FCF6D.E5B49458@giwersworld.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?

	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)

From: Ron Parker
Subject: Re: Macro with variable number of parameters...
Date: 4 Jul 1999 17:58:41
Message: <3780d89d.19745903@news.povray.org>
On Sun, 04 Jul 1999 17:17:33 -0400, Matt Giwer
<mgi### [at] giwersworldorg> 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

From: Jon A  Cruz
Subject: Re: Macro with variable number of parameters...
Date: 4 Jul 1999 19:08:44
Message: <377FE9AB.68BBED2D@geocities.com>
Ron Parker wrote:

> On Sun, 04 Jul 1999 17:17:33 -0400, Matt Giwer
> <mgi### [at] giwersworldorg> 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

From: Ron Parker
Subject: Re: Macro with variable number of parameters...
Date: 4 Jul 1999 19:42:48
Message: <377ff088.25869550@news.povray.org>
On Sun, 04 Jul 1999 16:09:31 -0700, "Jon A. Cruz"
<jon### [at] geocitiescom> wrote:

>Ron Parker wrote:
>
>> On Sun, 04 Jul 1999 17:17:33 -0400, Matt Giwer
>> <mgi### [at] giwersworldorg> 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

From: Jon A  Cruz
Subject: Re: Macro with variable number of parameters...
Date: 4 Jul 1999 23:15:46
Message: <37802390.741857A7@geocities.com>
Ron Parker wrote:

> On Sun, 04 Jul 1999 16:09:31 -0700, "Jon A. Cruz"
> <jon### [at] geocitiescom> wrote:
>
> >Ron Parker wrote:
> >
> >> On Sun, 04 Jul 1999 17:17:33 -0400, Matt Giwer
> >> <mgi### [at] giwersworldorg> 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] fwicom> 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

From: Dick Balaska
Subject: Re: Macro with variable number of parameters...
Date: 6 Jul 1999 01:37:33
Message: <378195ED.C9648CE2@buckosoft.com>
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] buckosoftcom> 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

From: Dick Balaska
Subject: Re: Macro with variable number of parameters...
Date: 7 Jul 1999 20:04:05
Message: <3783EABD.AA76F9B0@buckosoft.com>
Nieminen Mika wrote:
> 
> In povray.general Dick Balaska <dic### [at] buckosoftcom> 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] buckosoftcom> 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

<<< Previous 7 Messages Goto Initial 10 Messages

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.