variadic-functions

Pass variable-length arguments to another function expecting the same?

送分小仙女□ 提交于 2019-12-12 10:56:35
问题 How to code this right in Scala? def myFun(strings: String*) = { // do something... } def myWraper(strings: String*) = { // do something else and then call myFun with the dame input myFun(strings) } I've tried putting an asterisk like def myWraper(strings: String*) = { // do something else and then call myFun with the dame input myFun(strings*) } But this doesn't seem to work... 回答1: Try this: myFun(strings: _*) You need to tell it to split strings up across the varargs. 来源: https:/

Is va_start (etc.) reentrant?

寵の児 提交于 2019-12-12 10:49:50
问题 While making an edit to a class with a long history, I was stymied by a particular habit of the architect of wrapping his va_start -> va_end sequence in a mutex. The changelog for that addition (which was made some 15 years ago, and not revised since) noted that it was because va_start et. all was not reentrant. I was not aware of any such issues with va_start, as I always thought it was just a macro for some stack-pointer math. Is there something here I'm not aware of? I don't want to change

Java automatically converting collections to arguments arrays?

本小妞迷上赌 提交于 2019-12-12 10:31:21
问题 I know that the Java "..." array argument syntax can receive as a parameter an array, or just many parameters passed to the method. However, I noticed that it does so for Collections too: public static void main(String[] args) { Collection<Object> objects = new ArrayList<>(); test(objects); } public static void test (Object...objects) { System.out.println("no compile errors"); } This compiles and runs without me needing to call the toArray() method. What is happening behind the scene? Are

Is there a Java 1.5 varargs API for slf4j yet?

坚强是说给别人听的谎言 提交于 2019-12-12 09:28:53
问题 I want to get rid of this lot... public void info(String msg); public void info(String format, Object arg); public void info(String format, Object arg1, Object arg2); public void info(String format, Object[] argArray); ...and replace it with this one... public void info(String format, Object ... args); ...so that my logging syntax doesn't have to change depending on the number of arguments I want to log. There seems to be lots of discussion and work around it, but where is it? Or should I

How can I sent an array of strings into an UIActionSheet varargs init method?

你离开我真会死。 提交于 2019-12-12 08:46:18
问题 I have an action sheet with options that vary depending on the circumstances. There are enough different button titles that I would like to construct an array of those button titles first, but I can't figure out how to convert that into the varargs format. I want to do something like this: NSMutableArray *buttonTitles = [NSMutableArray array]; if (condition1) { [buttonTitles addObject: @"Do action 1"]; } if (condition2) { [buttonTitles addObject: @"Do action 2"]; } if (condition3) {

Overriding a variadic method in objective-c

拈花ヽ惹草 提交于 2019-12-12 08:26:28
问题 When subclassing in objective-c, how can I forward a call to the superclass in the case of a variadic method. By what should I replace the ??? below to send all the objects I got? - (void) appendObjects:(id) firstObject, ... { [super appendObjects: ???]; } 回答1: You can't. To safely pass all the variadic arguments, you need a method to accept a va_list . In super, -(void)appendObjectsWithArguments:(va_list)vl { ... } -(void)appendObject:(id)firstObject, ... va_list vl; va_start(vl, firstObject

Couldn't implement function with variable arguments

扶醉桌前 提交于 2019-12-12 07:28:31
问题 I was trying to implement function with variable arguments but was getting garbage values as output.I have referred to this article before trying to implement on my own.Could anyone help me out with this code as I am unable to understand what's wrong in this code. /* va_arg example */ #include <stdio.h> /* printf */ int FindMax (int n, ...) { int i,val,largest,*p; p=&n; p+=sizeof(int); largest=*p; for (i=1;i<n-2;i++) { p+=sizeof(int); val=*p; largest=(largest>val)?largest:val; } return

Pass multidimensional array as parameter to Postgresql function

五迷三道 提交于 2019-12-12 05:14:03
问题 I'm trying to maintain a Php application with a PostgreSQL database. At one point, a stored procedure is called, lets say function_x and inside function_x , function_y is called; function_y is passed a variable named parameter_1 , and the definition of parameter_1 is: parameter_1 numeric[][3] := {}; I'm trying to do a select function_y directly on the command line (or pgadmin) but I'm having problems passing an empty array into the function. according to the docs you have to use variadic but

Groovy: Detecting when being passed arrays

怎甘沉沦 提交于 2019-12-12 04:52:11
问题 The function f in the following code simply attempts to print out it's arguments and how many it receives. However, it expands array parameters (but not arraylists) as illustrated on the line f(x) // 3 . Is there anyway to get f not to expand array parameters, or alternatively at the very least detect that it has happened, and perhaps correct for it. The reason for this is because my "real" f function isn't as trivial and instead passes it's parameters to a given function g , which often isn

Is va_start required in variadic arguments for functions?

独自空忆成欢 提交于 2019-12-12 01:46:23
问题 I'm reading the text The Linux Programming Interface and they show this function to handle errors. In the man pages ( man stdarg ) it says va_start must be called first to initialize ap for use by va_arg() and va_end . So why in this function there is no va_start ? static void outputError(Boolean useErr, int err, Boolean flushStdout, const char *format, va_list ap) { #define BUF_SIZE 500 char buf[BUF_SIZE], userMsg[BUF_SIZE], errText[BUF_SIZE]; vsnprintf(userMsg, BUF_SIZE, format, ap); if