variadic

how to parse multiple returns in golang

旧巷老猫 提交于 2019-12-07 13:11:39
问题 I have a Go function which returns two integer values. Below is the function func temp() (int, int){ return 1,1 } Is it possible to put temp function directly into a Println and print both the outputs using string formatting as below: fmt.Println("first= %d and second = %d", temp() ) // This doesn't work In Python, I am able to do the following: def func(): return 1,1 print("{0}={1}".format(*func()) >> '1=2' Can I do Something similar in Go too? 回答1: First, for what you attempt to do you

Variadic C function printing multiple 2-D char arrays

£可爱£侵袭症+ 提交于 2019-12-06 16:29:14
I need to set up a variadic function in C that prints a variable number of 2-D char arrays side-by-side. I'm having a hard time figuring out how to initialize the boards variable with va_arg() . The key problematic line is: boards[i] = va_arg(ap, char*[][BOARDSIZE]); The line produces a compiler error (currently, Second argument to 'va_arg' is of incomplete type 'char *[][10]' ), but basically I'm sure I'm not doing something right. I'm just not sure what that something is. I've tried several variations to no avail. The rest of the code should be okay though. (Thank you in advance for any help

Expanding a macro to a different default macro if an argument is missing

南笙酒味 提交于 2019-12-06 11:25:18
Is it possible to expand a macro which accepts multiple arguments to a different macro if first argument is not the expected value E.g int main() { PRINT(2, "%d%d\n", i, j); //should expand to syslog(2, "%d%d\n", i, j) PRINT("%d%d\n", i, j); //arg1 which is expected to be an int is not preset. /* This should expand differently may be to a default level say 3. syslog(3, "%d%d\n", i,j); */ } I would have tried this kind of over loading if I knew total number of args. I really recommend to write two separate macros for this, just as you would write two differently named functions for the two

how to parse multiple returns in golang

北战南征 提交于 2019-12-06 02:37:35
I have a Go function which returns two integer values. Below is the function func temp() (int, int){ return 1,1 } Is it possible to put temp function directly into a Println and print both the outputs using string formatting as below: fmt.Println("first= %d and second = %d", temp() ) // This doesn't work In Python, I am able to do the following: def func(): return 1,1 print("{0}={1}".format(*func()) >> '1=2' Can I do Something similar in Go too? First, for what you attempt to do you should use fmt.Printf() instead of fmt.Println() as only the former expects and uses a format string. Going

Concatenation of tokens in variadic macros

白昼怎懂夜的黑 提交于 2019-12-06 01:30:23
In C, is it possible to concatenate each of the variable arguments in a a variadic macro? Example: MY_MACRO(A, B, C) // will yield HDR_A, HDR_B, HDR_C MY_MACRO(X, Y) // will yield HDR_X, HDR_Y The normal ## operator has special meaning for variadic macros (avoiding the comma for empty argument list). And concatenation when used with __VA_ARGS__ takes place with the first token only. Example: #define MY_MACRO(...) HDR_ ## __VA_ARGS__ MY_MACRO(X, Y) // yields HDR_X, Y Suggestions? First, the comma rule you are mentioning is a gcc extension, standard C doesn't have it and most probably will never

Ltac : optional arguments tactic

早过忘川 提交于 2019-12-05 21:47:07
I want to make a Ltac tactic in coq which would take either 1 or 3 arguments. I have read about ltac_No_arg in the LibTactics module but if I understood it correctly I would have to invoke my tactic with : Coq < mytactic arg_1 ltac_no_arg ltac_no_arg. which is not very convenient. Is there any way to get a result like this ? : Coq < mytactic arg_1. Coq < mytactic arg_1 arg_2 arg_3. We can use the Tactic Notation mechanism to try to solve your issue because it can handle variadic arguments. Let's reuse ltac_No_arg and define a dummy tactic mytactic for the purposes of demonstration Inductive

Passing arguments to another variadic function

走远了吗. 提交于 2019-12-05 16:19:25
Is there any way at all for this code to compile and work as intended without resorting to va_list stuff ? #include <iostream> void fct(void) { std::cout << std::endl; } void fct(int index, int indexes...) { std::cout << index << ' '; fct(indexes); //or fct(indexes...); ? } int main(void) { fct(1, 2, 3, 4, 5, 6, 7); return 0; } I suspect you have misunderstood the meaning of the signature void fct (int index, int indexes...) I suspect you think that fct() expect a int single value ( index ) and a variadic list of int 's ( indexex... ) with C++11 style of parameter pack expansion. No: it's the

How to write C function accepting (one) argument of any type

孤街浪徒 提交于 2019-12-05 05:13:34
I am implementing simple library for lists in C, and I have a problem with writing find function. I would like my function to accept any type of argument to find, both: find(my_list, 3) and find(my_list, my_int_var_to_find) . I already have information what is type of list's elements . For now I've found couple of ways dealing with this: different function with suffix for different types: int findi(void* list, int i) , int findd(void* list, double d) - but I don't like this approach, it seems like redundancy for me and an API is confusing. using union: typedef union { int i; double d; char c;

Extract just the argument type list from decltype(someFunction)

拈花ヽ惹草 提交于 2019-12-05 04:58:32
I have a variadic template that represents a list of parameters for a function, eg: void myFunc (int,int,std::string) { } template<typename... Args> class MyTemplateClass { }; ... MyTemplateClass<int,int,std::string> myConcrete; // for use with myFunc later Is there any way I can extract just the argument types from decltype(func) to save having to write them manually, eg: MyTemplateClass<something_like_decltype(myFunc)> myConcrete; ie decltype in this case would give me "void(int,int,string)" but is there a way of extracting just the "int,int,string" part for use in the variadic template?

Variadic macros with 0 arguments in C99

一曲冷凌霜 提交于 2019-12-04 18:28:08
问题 I have some debugging code that looks like the following: #define STRINGIFY(x) #x #define TOSTRING(x) STRINGIFY(x) #define AT __FILE__ ":" TOSTRING(__LINE__) void __my_error(const char*loc, const char *fmt, ...); #define my_error(fmt, ...) __my_error(AT, fmt, ##__VA_ARGS__) The last macro is used so I can insert the location into the debug output as to where the error occurred. However, when I call the function like this: my_error("Uh oh!"); I would like my code to be C99, so I find when this