2,730 questions
1
vote
1
answer
181
views
C++20: Encode and decode parameter pack as a variable to be used by varargs
Not sure if the following is possible in C++20 after a long and exhaustive search but asking anyway:
Using C++20 instead of C's va_list, can I:
(1) Encode arbitrary argument lists passed to a variadic ...
0
votes
1
answer
154
views
identifier "va_list" is undefined in Code Composer Project
I am use TI 8.3.11 (Code Composer Studio) Device Family C6000, SYS/Bios 6.67.3.01
I have a problem with variadic function, which accepts a variable number of arguments. My class:
#include "stdint....
0
votes
1
answer
94
views
Variadic number of dynamically allocated arrays
I have a bunch of dynamically allocated arrays (scoped to the entire program):
double* Ux{nullptr};
Ux = (double*) fftw_malloc( sizeof(double) * dataSize);
which are usually initialized according to:
...
1
vote
3
answers
193
views
call empty varargs method, when it is overloaded with an empty method
Spring's UriComponentsBuilder has
an empty build() method, as well as variadic build(Object... urivariables).
I want to call the second one with an empty array. Is there a better way to do so, then
...
0
votes
1
answer
38
views
i am not able to load what is on the file in the list of argument in c language why?
#include <stdio.h>
#include <stdarg.h>
void open(FILE *file,...){
va_list content;
va_start(content, file);
vfscanf(file, "%s",content);
printf("%s",...
1
vote
2
answers
127
views
Bind both lvalues and rvalues to variadic class template parameter
I have a class template that take a variadic number of template arguments. The class has some functions that take arguments corresponding to the class's template parameters. I would like these ...
5
votes
2
answers
326
views
Creating a variadic function that prints any kind of format of ("c", "f", "i", "s"), but doesn't work
I've created a struct, that groups the format character and a pointer to the function which prints according to the formatter.
typedef struct formatter
{
char spec;
void (*print)(va_list);
} fmt;
...
1
vote
1
answer
154
views
Collecting return types from vararg Callable for use elsewhere in signature?
I have the following function signature:
Y = Annotated[TypeVar("Y"), "That which might be yielded"]
R = Annotated[TypeVar("R"), "That which might be returned"]
...
0
votes
1
answer
112
views
how to avoid implicit conversion of arguments leading to infinite recursion?
I have a formatting method that I adapted from this example.
I have reduced it to just function calls and a print
It works when the formatting string (first argument) is a const char *
#include <...
2
votes
3
answers
5k
views
Is it possible to emulate variadic generics in Rust?
Rust is missing Variadic Generics (and also variadic functions) as a language feature.
Since it doesn't directly support these, is it possible to emulate the behavior in some way?
I suspect this might ...
0
votes
1
answer
98
views
How can I use DataTypes key as arguments
I have a macro that works as expected, but I want to make some changes to make it cleaner to use.
#define FuncCreate(func_name, func, ...) \
int func_name(lua_State *ms) { \
func(__VA_ARGS__); ...
2
votes
0
answers
224
views
Type hinting instances vs types with variadic generics
This is a question for the type hinting pros among you.
I have the following construct and I'm wondering if there is a way to corrctly add type annotations to it as it is. This is from the Qt ...
0
votes
3
answers
103
views
How to pass parameter to invoke method as a vararg of a relfected class in case of Java reflection?
I have a project in which I am using a third party library. However, I need to call methods from the third party only if the user has copied those jars in the project, or else use the existing jars. ...
-1
votes
1
answer
240
views
printf: Mixing va_list and varargs
I have a logging function which is implemented along the following lines. The basic idea is that I want to give the user printf-like formatting, but to prefix the logged string with a timestamp and ...
1
vote
1
answer
567
views
JUnit MethodSource with single array varargs problems
I have a problem with single/multiple arrays as varargs parameters used in JUnit5 MethodSource's Arguments.
If multiple arrays (empty or not) are passed, everything's fine, but if only a single array ...
0
votes
0
answers
225
views
How can I create a method with a variable number of arguments in a class with Q_OBJECT? [duplicate]
This post is not just about unresolved linker symbols in general, but about a variadic function in a class with a Q_OBJECT macro. The macro creates a lot of components automatically generated by the ...
0
votes
1
answer
92
views
Freeing memory with a variadic function in CUDA
I wrote a function similar to the one described in this answer to a SO post about freeing with a variadic function in the C language but for CUDA vectors.
Here is the function:
void freeCudaVectors(...
1
vote
1
answer
407
views
How to call a matlab function specifying explicitly every argument
I am wondering if i can create (and call) a function where i can specify the arguments explicitly, like this:
myFun(arg1 = 1, arg3 = "test_string")
where
function = myFun(arg1,arg2,arg3)
...
1
vote
0
answers
170
views
how to combine paste() and print() in the R language?
I would like to combine the paste and print functions. This is the best I can do so far:
pp <- function(...) {
s<-paste0(list(...), sep="")
}
foo<-"foo"
s<-paste0(foo,...
0
votes
1
answer
116
views
Vector of tuples of same indexed-elements; determine whether vectors are of same size
I am looking to create a vector that stores a tuple of the same-index elements from different vectors.
Although I am able to achieve it, there's a caveat if the caller passes in vectors of different ...
0
votes
1
answer
69
views
Add arguments to a function acording to user input
I'm sorry in advance for my English, it is not my native speaking language. I'm running this in Python
I have a XML-RPC function and, as part of its parameters, there are some filters that you can ...
0
votes
1
answer
133
views
CPP issue using variadic parameters (Args...) to log
I'm trying to log some things on my cpp app.
I chose to go on variadic parameters.
My log functions :
inline void log() {}
template<class... Args>
inline void log(std::string_view first, const ...
1
vote
1
answer
119
views
Call function with variable number of arguments
I've a function
int send_email(const char * to, const char * subject, const char * body, size_t nbr_attachments, ...);
it all works fine. I can use it for sending an email with no attachments:
...
1
vote
2
answers
278
views
Variable arglists in Ada
Why does not Ada support variable function/procedure argument lists?
Is it hard to implement or does it somehow go against "we should keep things secure" philosophy of the language?
Varargs ...
0
votes
0
answers
87
views
Using partially applied functions in Scala [duplicate]
I am a newbie in Scala and am trying to understand partially applied functions. I can implement simple examples like when function takes two integers as input. But I wanted to combine variable number ...
3
votes
1
answer
245
views
what diffrence is List.of(E e1, E e2, E e3) vs List.of(E... elements)
List.of(E e1, E e2, E e3) return ImmutableCollections.ListN(e1, e2, e3);
static <E> List<E> of(E e1, E e2, E e3) {
return new ImmutableCollections.ListN<>(e1, e2, e3);
}
and ...
0
votes
3
answers
268
views
Сall the add function on every next 2 arguments
I have a function that does some arithmetic on two elements like this:
template <typename Type>
Type add(const Type& a, const Type& b)
{
// some logic
if(!((b >= 0) &&...
1
vote
2
answers
515
views
How to get max length of a number of strings at compile time?
(Update: I am programming for microcontrollers, so I am short of memory and computation power. Therefore I am limited to C-strings.)
I have a number of strings and want to find the maximum length of ...
2
votes
2
answers
333
views
Implementation of printf() in C using the write() syscall
I am trying to not only return the output to the stdout but also trying to return the size of each data type that would be tested. I am using the write() syscall to write the simple output to the ...
6
votes
0
answers
520
views
How do I get printf-like warnings with variadic arguments?
If I compile g++ with -Wformat on the following code, I get a warning, as expected.
int main(int argc, char * argv[])
{
printf("argc %lld\n", argc);
}
However, if compile the following ...
2
votes
1
answer
187
views
Overload resolution with parameter pack
Say I have these two methods:
// Overload 1
template <typename T, typename... Args>
void Foo(Args&&... args)
{
// do things with T, args...
}
// Overload 2
template <typename T, ...
0
votes
0
answers
76
views
Calling functions with unknown number of arguments
I have the following struct:
// fninfo holds a function and its arity.
type fninfo struct {
arity int // number of arguments that fn takes
fn any // fn must take string arguments and return ...
0
votes
1
answer
88
views
Variadic template class containing array of another template class
I'm creating my own RDBMS to practice C++. I came up with a solution where each column can have a type and is a template. This is what a row looks like, but it doesn't work
template <typename... ...
0
votes
2
answers
156
views
get the first with specific type in a variadic function
this is my 2nd post and i tried to find as much information before posting here as i could (including the new possibility with chatgpt) to understand some more the work of variadic function. The first ...
2
votes
1
answer
123
views
Using an undefined (misspelled) argument in `paste` function - understand the result
We all know there is a collapse argument in paste() function. It refers to an optional character string to separate the results:
paste(1:5, collapse = ", ")
[1] "1, 2, 3, 4, 5"
...
1
vote
1
answer
297
views
Return type of varargs and generics
I was learning Java about how varargs works with the generic types. There was this function when I tried to return an array of generic types, which in this case T is String
static <T> T[] toArr(...
0
votes
1
answer
64
views
Parameter pack unpacking returns default object in thread pool
I am currently tasked with writing a generic thread pool, having multiple worker threads and one scheduling thread in c++. To support running any kind of function within one pool I used variadic ...
3
votes
1
answer
78
views
Effect of default argument promotions on wchar_t
I am a bit confused about how default argument promotions effect wchar_t.
I understand that char is promoted to int, and therefore I have to supply int as the second parameter of va_arg, otherwise I ...
15
votes
1
answer
805
views
Is it legal to pass va_list as a reference to a function in C++?
Upon code review/clang-tidy runs, I came across a function with a signature like this:
void appendFoo(const char * fmt, va_list& rVaList);
I have never seen this before.
Afaik, you can pass ...
2
votes
2
answers
453
views
C variadic function: need to keep multiple va_list but old ones are overwritten by latest one
I run this in MSVC v142.
I need to keep multiple va_list and then pass all of them in an array to another API.
However, the old va_list were getting overwritten by the newer one.
void toVaList(va_list ...
3
votes
1
answer
394
views
Express function of arbitrary arity in vanilla Scala 3
Trying to grasp Scala 3 type system.
Question:
Is it possible to write a single universal def curry(f: ???) = ... function that accepts f of any arity and returns a curried fn? No compiler plugins, ...
0
votes
1
answer
17
views
after trimming a string in php the string length is same is showing
?php
$a=" just wait ";
echo "Before trimming string length=".strlen($a)."<br>";
echo trim($a)."<br>";
echo "After trimming string length="....
0
votes
0
answers
71
views
How to iterate over a template-less variadic in C++
I was under the impression that I don't need a template in order to use variadics in C++. So in the following class, I have a method that accepts a variadic as its second variable. Now my question is: ...
0
votes
1
answer
85
views
Why does this variadic function code produce random results on every run?
As double and unsigned long are the same size, va_arg should pop the equal number of bytes from the stack and the value displayed should be the same every time the program is run since the double ...
0
votes
1
answer
114
views
Partial function application in Scala for arbitrary input arguments
I am wondering whether the following is possible in Scala:
Given some vector x = (x_1, x_2, ..., x_n) in R^n and a function f that maps R^n to R, I would like to replicate this concept in Scala. The ...
1
vote
1
answer
134
views
address of a va_list variable is not allowed? Error: assignment from incompatible pointer type?
Code to duplicate this on Linux is as follows:
GCC 4.8.5 20150623 (Red Hat 4.8.5-44)
No i can't change this, it's on CentOS7 and its a requirement to stay there)
#include <stdarg.h>
struct foo {...
0
votes
1
answer
103
views
Correct use of param-no in GNU C's printf format specification
I am working on a helper function using printf format strings, so I started to examine printf format specifications in more detail, and found that GNU's manual allows the use of a param-no: https://...
0
votes
1
answer
24
views
Using rest parameter to make functions adaptable in various contexts
Noob programmer here,
I find myself using the rest parameter often, as a way of keeping my functions adaptable early when I don't know all the variables types/arguments.
I would like to develop a ...
0
votes
0
answers
31
views
C vprintf Modify va_list Argument [duplicate]
I'm trying to write a function that intermixes calls to vprintf with usages of the variadic arguments. However, the behavior I am observing does not match my expectation. The following is code that ...
2
votes
1
answer
144
views
variadic function in golang
package main
import (
"fmt"
)
type ISum interface {
sum() int
}
type SumImpl struct {
Num int
}
func (s SumImpl) sum() int {
return s.Num
}
func main() {
nums := []...