Jump to content

Large number of parameters?


 Share

Recommended Posts

Prompt please, is it possible using AutoIt define a function with a large number of parameters of the same type do not list them in the title of this feature.

For example:

MyFunc (value1, value2 [, value n])

And how to obtain these parameters in the loop.

If it is not possible, then why there is a macro @NumParams.

:P

Link to comment
Share on other sites

As a pretty irrelevant tidbit of info I'd like to say that this concept is typically called a "variable length argument list". It is present in Java by default and is present in c/c++ by some sort of include if I recall correctly. Google it to find out more. I am pretty sure AutoIT does not support it, but to be honest that isn't a big deal, just throw your arguments into an array and pass that instead. It's really a pretty unnecessary construct IMHO, though it can make code more concise at times.

Link to comment
Share on other sites

I wanted to write a function like BitOR (). But to enumerate all the parameters is absurd. :P

func Problem($v1, $v2, $v3, $v4, $v5, $v6, $v7, $v8, $v9, $v10, $v12, $v13, $v14, $v15, $v16, ..., $v255) :wacko: 
    if $v1 = 0 then
    if $v2 = 0 then
    if $v3 = 0 then
    ...
endfunc

How to use the @NumParams?

Thanks.

Edited by Yashied
Link to comment
Share on other sites

Like Wus said, an array would be easiest.

Global $aArr[5]

$aArr[0] = "Something"
$aArr[1] = "Goes"
$aArr[2] = "Here"
$aArr[3] = "Okay"
$aArr[4] = "Good"

_ParesParams ($aArr)

Func _ParesParams ($aParams)
    $total = UBound ($aParams)
    MsgBox (0, "", "THere are " & $total & " params")
EndFunc

Cheers,

Brett

Link to comment
Share on other sites

As Wus said, AuotIt doesn't have any "variable length argument list", if you want to shorten the code use an array instead (that would also have the added benefit of being able to have 16 million parameters instead of 250)

Link to comment
Share on other sites

As a pretty irrelevant tidbit of info I'd like to say that this concept is typically called a "variable length argument list". It is present in Java by default and is present in c/c++ by some sort of include if I recall correctly. Google it to find out more. I am pretty sure AutoIT does not support it, but to be honest that isn't a big deal, just throw your arguments into an array and pass that instead. It's really a pretty unnecessary construct IMHO, though it can make code more concise at times.

Technically it's supported natively. The header you refer to just provides some convenience macros so the programmer doesn't have to offset memory addresses manually.
Link to comment
Share on other sites

As Wus said, AuotIt doesn't have any "variable length argument list", if you want to shorten the code use an array instead (that would also have the added benefit of being able to have 16 million parameters instead of 250)

The array is not the solution. In this case, can I pass a pointer and then get more than 16 million. I would like to obtain a compact and a nice function. Who can answer anything about the appointment @NumParams?

Link to comment
Share on other sites

But offsetting memory addresses is so much more fun.

I just wish C++ had a type safe variable argument list.

That is an oxymoron. You can't be type-safe if you don't know what you are expecting. If you do know what you are expecting then it doesn't need to be variable. If you need to accept a variable number of arguments of the same type, a vector or other container would be best. However, you could always roll your own using RTTI to verify the objects.

The array is not the solution. In this case, can I pass a pointer and then get more than 16 million. I would like to obtain a compact and a nice function. Who can answer anything about the appointment @NumParams?

It contains the number of parameters passed when optional parameters are used.

What you are trying to do is not possible to do without using an array or explicitly declaring a function that takes 255 (mostly) optional parameters. With proper naming Eval() can be used to write short code but performance is going to suffer. Something like this would be a start:

Func Test($v1 = 0, $v2 = 0, $v3 = 0, ..., $v255 = 0)
     For $i = 1 To @NumParams
         ConsoleWrite(Eval("v" & $i) & @CRLF)
     Next
 EndFunc
Edited by Valik
Link to comment
Share on other sites

Technically it's supported natively. The header you refer to just provides some convenience macros so the programmer doesn't have to offset memory addresses manually.

Hmm, thanks for the info, I didn't know that. To be honest I've never really had the need to use variable length argument lists in c++. Now that I think on it a bit, the only place I have ever used variable length argument lists is for things like max functions, since it seems like you always need 2, 3, and 4 argument versions and variable length argument lists are the most terse way of doing it as far as I know.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...