499 questions
2 votes
3 answers
276 views
Why void() redefines a function in C++?
Given this function: int f() {return 10;} void(f()) defines a void f() and doesn't compile with the following error: 'void f(void)': overloaded function differs only by return type from 'int f(void)'...
0 votes
0 answers
100 views
Can I trigger a compiler warning, and no linking error, with a templated declaration only?
I want to write a declaration, templated on a type, such that: If not instantiated, triggers no compiler warnings or errors, even with strict warning flags. If instantiated (e.g. by being used), ...
5 votes
1 answer
173 views
Local scope constant as function's default argument
Can function declaration in a function scope have a locally defined constant as default argument? For example, void f(int) {} int main() { constexpr int c = 1; void f(int = c); f(); } ...
0 votes
3 answers
144 views
Use of const keyword with array pointers in C
In the 9th edition of Deitel's book C. How to program (chap. 7), a function is declared as void bubbleSort(int * const array, size_t size) and in the text it's specified that "function ...
4 votes
6 answers
273 views
Function returning 101 and -101 instead of 1 and -1
So my professor gave us the assignment to code a function that works exactly like strcmp() but without using any library functions. I came up with the following code but instead of returning 1 or -1 ...
0 votes
2 answers
97 views
Is it legal to have a function prototype slightly different from its definition?
//my_struct.h typedef struct my_struct_t *my_handle; void f1(my_handle handle); void f2(my_handle handle); //my_struct.c #include "my_struct.h" typedef struct { int a; int b; } ...
0 votes
2 answers
94 views
Avoid names of variables ending into function definitions in R
I would like to use values within variables for defining functions in R. However, after declaring the function I can still see the variable names instead of their values inside the function definition....
0 votes
0 answers
129 views
what does "auto(*)" mean in "auto(*)(int, int)->bool"? [duplicate]
#include <vector> #include <queue> #include <functional> using namespace std; int main() { priority_queue< int, vector<int>, auto(*)(int, int)->bool > que1; ...
4 votes
2 answers
141 views
Function definition with prototype vs without prototype
There are (source): void f(); // declaration (1) void f(void); // declaration with prototype (2) void f() { ... } // definition (3) void f(void) { ... } // definition with ...
-4 votes
2 answers
97 views
re assign array with new list of values
Suppose I have a function: void function(int a[3]) {/*..*/} What is the efficient way of calling this function with values in place I want to calling as below without creating a new local array[3] ...
2 votes
3 answers
98 views
Understanding Function Definitions that Return a Function Pointer
I am hoping to get some help with understanding why function definitions, with function pointer return types need to be written the following way. int ( * functionFactory (int n) ) (int, int) { ...
1 vote
3 answers
145 views
Declaring a function with different function specifiers
Consider this C code: _Noreturn void exit(int status); void exit(int status); int main(void) { exit(0); } It declares the exit function twice, once with the _Noreturn function specifier, and ...
5 votes
2 answers
187 views
Is it standard C17 to wrap a parameter in a function declaration in parenthesis
Is the following a standard C function declaration according to ISO/IEC 9899:2017 (c17)? int foo(int (bar), int (baz)); If so, please point me to the section in the standard that defines this. In ...
2 votes
4 answers
405 views
Why is the mismatch between declaration and definition not raising error during compilation?
I have two source files, main.cpp and math.cpp, along with a header file math.h. The code is as follows: // main.cpp #include "math.h" #include <iostream> int main() { std::cout &...
2 votes
1 answer
157 views
How to declare a const and non-const operator overload in one declaration (templately)?
INTRO I am writing a class stalker<Obj> that holds inside a variable of type Obj. I want that stalker<Obj> to pretend that it is almost the same as Obj variable (from the user's ...