331 questions
1
vote
3
answers
237
views
Why can't I declare int n[][] but I can declare int (*n)[] as a parameter?
The C23 standard says(6.7.7.4 #7):
A declaration of a parameter as "array of type" shall be adjusted to
"qualified pointer to type", where the type qualifiers (if any) are
those ...
0
votes
1
answer
55
views
How is a lambda invoked here without the need of a function parameter?
Learning about flows and the interface definition is this:
interface Flow<out T>{
suspend fun collect(collector: FlowCollector<T>)
}
collect has no function parameter yet I'm allowed ...
0
votes
2
answers
185
views
Why does this function not modify the original array when passed as a parameter?
#include <stdio.h>
void modifyArray(int arr[]) {
arr = (int[]){6, 7, 8, 9, 10}; // Trying to modify the array
}
int main() {
int arr[] = {1, 2, 3, 4, 5};
modifyArray(arr);
for (...
-3
votes
2
answers
164
views
C++ format specifiers in custom functions
Is it possible in C++ to use format specifiers in a custom function?
Like as in the printf() statement, and how you can use e.g. '%d' to insert an int variable:
printf("The number is %d", ...
0
votes
0
answers
84
views
Difference between using [[maybe_unused]] and omitting parameter names [duplicate]
I'm trying to suppress compiler warnings for unused function parameters. I know of two methods:
Using [[maybe_unused]] in C++17 or later:
void foo([[maybe_unused]] int x) {
// x is unused
}
...
8
votes
3
answers
229
views
Is it enough to only restrict the "out"-(pointer-)parameters of a function?
Suppose I have a function which takes some pointer parameters - some non-const, through which it may write, and some const through which it only reads. Example:
void f(int * a, int const *b);
Suppose ...
-1
votes
3
answers
115
views
C++ function as a parameter where its parameter can be passed by value or by reference
I have the following functions where processArray is a generic function that is used to process an array. A function is passed to it as a parameter so that each element can also be processed.
template&...
0
votes
0
answers
33
views
Multiple function Parameters Without Declaration? [duplicate]
I want to have a function with infinite parameters but I don't want to declare them How do I do this?
function func(){
for(let i = 0; i < params.length; i++){
console.log(param[i]);
}
}
0
votes
0
answers
23
views
I can't access an array that was dynamically allocated inside the function [duplicate]
I want to allocate memory for a two-dimensional array of char in a separate function. I defined a double pointer in the main function, then I passed this pointer into my separate function alloc_arr(), ...
0
votes
3
answers
159
views
C++ Passing Parameters for a Function Pointer that is a Parameter to Another Function?
I want to write Breadth-First Search and Depth-First Search functions for a graph. But these functions should be able to take a function as a parameter so I can pass each node in the graph to the ...
3
votes
1
answer
93
views
C++ using a class name and a "normal" variable as a constructor parameter simultaneously
Dear Experts my concept is the following: I have some structured data (in struct F_data), and I want to fit various function on this data (eg. parabola, hyperbola etc.). Therefore I have a base class (...
0
votes
2
answers
345
views
"some" keyword with variadic parameter in Swift
protocol myProtocol {}
func doSomething(with params: (some myProtocol)...) {
// Implementation goes here
}
extension Int: myProtocol {}
doSomething(with: 1, 2, 3)
Compilation error at the func ...
1
vote
2
answers
66
views
Using multiple overloads of a function in variadic template
I would like to pass an overloaded function as an argument for a variadic template function. I understand how to do it with one particular function (using static_cast). However, I am wondering if ...
0
votes
0
answers
31
views
Get the specific value of default nonatomic parameter
I need to use the function capwords() from SGP in the way to get approach to use the value of default parameter special.words extended with my additional words. I.e. I need to do somthing like:
...
2
votes
3
answers
137
views
cbind() - how to label a vector dynamically in one line
Consider:
cbind("1" = 1:4)
## giving.
1
[1,] 1
[2,] 2
[3,] 3
[4,] 4
What I am trying to achieve is replacing "1" with a function that returns a character expression, e.g.
...
3
votes
2
answers
149
views
When passing a contiguous array to a function, is it more preferable to pass a pointer and the size, or a begin-pointer and an end-pointer? [closed]
When designing a function that expects a contiguous array in the form of a pointer, should one pass the array using
A.
a pointer and the array's size:
void foo(int* arr, size_t size);
Or B.
a begin-...
1
vote
1
answer
73
views
a function pointer as a function paramter - should one const it? [duplicate]
If I write something as follows:
int f(char x, const int (*g) (const char x)) {
return g(x);
}
does the first const say effectively what I think it says, namely basically that the programmer can'...
1
vote
1
answer
107
views
Passing designated initializers for a template class to a template function
My goal is to create an API interface that looks like that this:
struct myAB{ int a,b; };
void function(myAB ab) {}
...
function({.a = 1, .b = 3});
The above works just fine. But if I want struct ...
1
vote
1
answer
59
views
Passing multi-line string to PowerShell function parameter
I have the following code:
function Main{
$param1 = @"
aaa
bbb
ccc
"@
Test -Param1 $param1
}
function Test {
param (
[Parameter(Mandatory)][string]$Param1
)
...
0
votes
2
answers
179
views
C Use an array variable in a function parameter?
I have a 2D array of strings char* d2Array[valueA][valueB].
This works fine, I am able to fill it with strings and access them. There is an issue when passing it to a function. You need to specify the ...
0
votes
2
answers
684
views
Function that receives a function and a "default parameters" key-value object and returns another function with default arguments set
That sounds kind of complex. The idea here is to write the method "defaultMethod". It receives a function and an object. If the function is a simple add:
function add(a,b) { return a+b;};
...
0
votes
1
answer
332
views
How to avoid using global variables when coding a game in C with the betty style?
I am new to coding and started off with C. I am trying to recreate the famous Snake game and currently using the betty style of coding. Apparently global variables are not allowed and so far What I ...
2
votes
1
answer
234
views
Moving parameter to data member: Take parameter by copy or rvalue-ref?
I have a class object entity which gobbles up a string and shoves it into it's member on construction (for the sake of this argument this could be any old member function).
Now I can do this in at ...
0
votes
1
answer
48
views
SQL Server make table as a function parameter
I have this function, and I want to make the table '[SEJ_Reservation]' as a parameter to the function, to be able to use the function with another table, the function as below :
CREATE FUNCTION [dbo].[...
1
vote
2
answers
96
views
How to restrict function parameters types base on if the index of parameter is even or odd in typescript?
What I'm looking for is to have a function with infinite number of parameters and each parameter type is based on if its index is even or odd.
A contrived example:
flow(isMachineReady(), 'and', ...
11
votes
3
answers
957
views
Is it valid to use a zero-sized non-static array function parameter?
Is it valid, according to ISO C (any version), to specify a zero-sized array parameter?
The standard seems ambiguous. While it's clear that zero-sized arrays are invalid, array function parameters ...
11
votes
3
answers
15k
views
How to pass a Composable to another Composable as its parameter and display/run it in Jetpack Compose
I have this drawer I learned to make on youtube
https://www.youtube.com/watch?v=JLICaBEiJS0&list=PLQkwcJG4YTCSpJ2NLhDTHhi6XBNfk9WiC&index=31
Philipp Lackner
I want to add the drawer to my app ...
1
vote
1
answer
43
views
Failure in Pointer Dereferencing in C while using same function and variable
I am trying to using C to work with files with different extensions. So this is the code that I have written.
#include <stdio.h>
#include <windows.h>
#include <unistd.h>
#include <...
0
votes
0
answers
140
views
Kotlin: mark function argument after sanitizing it into a new variable as "do not use this anymore"
To start: this question is already kind of resolved for me. But the discussion might be interesting.
I like code so let's look at this function:
fun foo(path: Path) {
val absPath = path....
1
vote
3
answers
1k
views
Why assigning an array item to variable can avoid TS possibly null error, but directly accessing it can't?
I would like to know the difference between assigning an array item to variable and accessing directly to it. As I show in the code below, #1 hits the possibly null error, but #2 and #3 doesn't. Those ...
2
votes
1
answer
169
views
PHP: Restrict class type in function parameter
I have inherited some code like this
public static function instanciateRepository( $repositoryClass, ... ) {
...
new $repositoryClass( ... );
}
Where $repositoryClass is a class type ...
3
votes
2
answers
701
views
TypeScript Array Union Type in function parameters
I have a union type of an Array of various specific lengths:
[ number ] | [ number, number ] | [ number, number, number, number ]
As you can see, there are requirements for an array with one element, ...
0
votes
1
answer
102
views
How do I use an equation as an argument in a function?
I have a an equation that i want to use as an argument in my function, the catch is i want to have it within my function without defining any of its variables. The idea is once have it inside my ...
2
votes
1
answer
468
views
r- Storing the warning messages without discarding results when using purrr::map
I have a list of inputs over which I loop using purrr::map.
Using a tweaked version of purrr::possibly (for more details see here)
Applying this version of "possibly" to my main function, I'...
0
votes
1
answer
230
views
Why copy intialisation is used instead of direct initialisation when passing argument to function parameter by value
I am learning C++ using the resources listed here. In particular, I came to know that copy initialization is used when passing arguments to function parameters(by value) etc.
For example, from decl....
0
votes
1
answer
98
views
Passing Class object as Global Param
I'm trying to pass a class object as an argument to a global function.
Here's the function:
def CreatePlayers(p1_Name, p2_Name, cardDeck):
#Function to Create Players
#Takes 3 variables: Names of ...
-1
votes
3
answers
65
views
Javascript function parameter query
Do javaScript accept multiple strings as a function parameter?
function name(Haydon Lyson){
//code
}
will it be accepted? If not then how can we pass multiple strings as function parameter.
0
votes
2
answers
761
views
How to write a function type to access nested key of object in typescript
I'm trying to write a function that will accept 2 parameters i.e key and subkey and return one of the properties of that nested object. I have successfully written the type for function but cannot ...
0
votes
1
answer
901
views
Using purrr::possibly to catch dynamic error messages
I've written a custom function that does a number of checks and throws a different error when a check fails.
Below is a simple example function that takes a data.frame and a column name and simply ...
-2
votes
2
answers
3k
views
Getting Previous declaration is here Error in C
Task: write a function to calculate the area of a square, rectangle, circle.
My code is right. IDK why I am getting this error complete error
#include<stdio.h>
#include<math.h>
int square()...
0
votes
1
answer
418
views
Funtions with two parameter not working in React
I have 2 files. One of them is "http" folder for requests, the other one is React Component. I have a problem when I want to change the form and upload a profile photo. Changing form is ...
0
votes
1
answer
27
views
Typescript Error : Declaring a parameter as a union of interfaces. Instead of picking one of the choices, it picks all of them
This is the code I want to write
interface InputField{
formHeading:string,
isText:boolean,
fields:any[]
}
interface InfoField{
formHeading:string,
isText:boolean,
textData:...
0
votes
1
answer
174
views
How to hint users to do the allocation in out parameter?
Assum I have some pure C code like this.
It is not the real code, just for an example.
struct Param {
struct InParam {
int a;
int b;
} in;
struct OutParam {
int *c;
} out;
};
...
-1
votes
2
answers
770
views
Is it true that when passing an argument to a function, it is like assigning the value to the parameter?
I am new to C++ and I am writing pseudo code here:
void fn(a) {}
fn(b)
It is correct to assume that in the function body fn what happens is this assignment
`a = b`
I know we can pass the reference/...
0
votes
1
answer
4k
views
How to pass an empty span object?
Is there a way to pass an empty std::span<int> to a function?
I have a function like below:
bool func( const std::vector<int>& indices )
{
if ( !indices.empty( ) )
{
/* ...
1
vote
1
answer
416
views
How can i pass parametres from vue function in component?
I've to call a function with parametres but i didn't find a correct solution for my problem. The NavigateTo should pass a String value to my index to switch it and navigate to the correct component(no ...
2
votes
1
answer
95
views
JS function parameters are declared but never read
I have an input in html and want to put the text of the input into an object on JS and display it on a tag on html as a result.
Because I didnt wanted to simplify the code, i tried to create a ...
2
votes
2
answers
101
views
Does 2D array need to know its size beforehand in C?
Comparing this 2 codes:
void foo(int rows, int cols, int **ar)
{
printf("%d\n", ar[rows - 1][cols - 1]);
}
and
void foo(int rows, int cols, int ar[rows][cols])
{
printf("%d\n",...
2
votes
2
answers
3k
views
TypeScript: Generic types for functions treat parameters as "any" despite declaring them otherwise
Using TypeScript 4.4.3, I want to be able to explicitly type function parameters to a function that returns a generic. TypeScript is ignoring the types for the parameters to functions that use ...
4
votes
4
answers
5k
views
conditional function arguments in typescript
Is it possible to have a conidial required argument type based on the first argument type:
type ConditionalRequiredArg<T, P> = T extends string ? P | undefined : P;
function func<T, P>(...