4,482 questions
-1
votes
3
answers
133
views
Can the value at the address pointed by a pointer be assigned to the address pointed by another pointer? And how can i solve this min-max problem in C
I have two questions.
MY CODE:
#include <stdio.h>
void arrayFonk(int *dizi, int size, int *minimum, int *maximum){
int i;
int b;
for(i = 0; i < size; i++){
if(*(dizi ...
0
votes
1
answer
101
views
Lambda cannot be passed to templated function which takes a function pointer
My Setup
I have these things setup,
A struct
A templated function pointer that takes that struct as parameter with T as return type
A templated method invoker that takes the callback of the function ...
2
votes
0
answers
58
views
Why do mutable borrow errors disappear when refining the type of a function pointer variable
In my function I need to rotate a VecDeque a certain amount of times, always in the same direction that depends on the input, with a value that never changes. So I started envisioning a solution like ...
1
vote
1
answer
84
views
How to implemented comparison/less operator for member method pointers?
From my reading, I understand that it is possible to compare some pointer types in C++ using either operator< or std::less. This is useful if, for example, a pointer is used as a key for a std::...
4
votes
1
answer
233
views
void* ptr = &func; compiles with msvc without any diagnostic but both gcc and clang rejects it
I am learning C++ using the book "C++ Primer" by Stanley. In particular, the section about "pointer conversions" says:
a pointer to any nonconst type can be converted to void*
...
1
vote
1
answer
123
views
Why aren't concept constraints considered contextual type information?
Consider:
void f(int); // (1)
void f(int, int); // (2)
auto pf1 = static_cast< void (*)(int) >(f); // Ok, address of (1)
auto pf2 = static_cast< void (*)(int, int) >(f); // ...
0
votes
1
answer
135
views
Pointer to OpenBLAS subroutines in fortran
In my code, I want to set pointers to OpenBLAS subroutines, to compile the code either in single or double precisions.
To do so, I define two modules and I define function interfaces for single(sgemv) ...
0
votes
1
answer
75
views
C++ function pointer to non static member function [duplicate]
I have 2 classes: MeshInput and VoxelGrid. VoxelGrid has the member sdf which is a function pointer. Now I want to assign a non static function of another class to sdf. I can't change the signature of ...
0
votes
2
answers
100
views
Function pointer not compiling cleanly
I am trying to familiarize myself with pointers to functions in C. I have looked online and found several examples of these. However, when I compile my program (using GCC [version (Debian 12.2.0-14) ...
3
votes
2
answers
120
views
How can I declare an array of pointers with blocks of NULL elems
I'm using an array of functions pointers, and I'd like to use it directly with their associated event IDs.
Problem is, event IDs start from 0x10 to 0x1C, and from 0x90 to 0xA5.
I don't want to write ...
1
vote
0
answers
96
views
Construct a callable argument in embedded Python with Python C API
I am writing code that starts in Python, then goes to C via ctypes and inside C it uses Python embedding to invoke a Python function, that is, the flow looks like this:
Python user code passes ...
2
votes
2
answers
111
views
passing member function const and non-const overload to std::function
I was trying to get "more fluent" with function pointer manipulation and I've got an issue with passing a member function to std::function when there are two overload: const and non-const. ...
1
vote
2
answers
67
views
Pointer variables generated in functions cannot be passed in parameters of function pointers
Topic:
Given a positive integer with no more than 5 digits, require:
Find out how many digits it is;
Output each digit separately;
Output each digit in reverse order. For example, if the original ...
2
votes
0
answers
64
views
How to call shared object function (loaded dynamically) from pointer in Go?
I try to call few shared object functions from Go. I don't want to write a C commented code to build a CGO interface for all functions.
I write my shared object like that:
#include <stdio.h>
...
1
vote
1
answer
110
views
Calling a member function pointer without using this
I've written the following class that looks up a keyword and executes the associated function.
#include <iostream>
#include <string>
#include <map>
class Example;
typedef std::map&...
0
votes
1
answer
42
views
Function pointer declaration misreads argument type [closed]
I have problems using a struct as an argument in the declaration of a function pointer (MyFunction) below:
#include <iostream>
struct Record {
int x, y;
};
// MyFunction returns a changed ...
-1
votes
1
answer
87
views
Function invocation in `std::bind`
TLDR: How does std::bind() actually work when calling a member function with an instance of a class or a this pointer of the class?
Notes:
I know what a function adapter and a function object are.
I ...
-5
votes
3
answers
335
views
What is the downside of replacing if statements with function pointers?
I am looking for optimizing my update loops, and got around to this code:
// Define two lambda functions
auto iftrue = [](int x, int y) -> int {
return x;
};
auto iffalse = [](int x, int y) -&...
0
votes
0
answers
38
views
Call a function with the address extracted from vector of lists, lists are address of functions
#include <list>
#include <vector>
#include <mutex>
typedef std::list<void *> funcList;
typedef struct {
funcList* functionsList;
char* listName;
}ListAccess_t;
namespace ...
0
votes
2
answers
111
views
pointer to member function in C++ [duplicate]
I have problem in this line std::cout << &X::a << std::endl; this line print 1 supposed to printed address of &X::a
this my code
#include <iostream>
#include <string>...
1
vote
1
answer
329
views
How can I cause indirect (function pointer) call to be correctly jump/branch predicted?
let's say I have a function that accepts a callback argument (example given in rust and C)
void foo(void (*bar)(int)) {
// lots of computation
bar(3);
}
fn foo(bar: fn(u32)) {
// lots of ...
-1
votes
1
answer
50
views
Compile error for function pointer to member function in C++
I am getting compile error C2064 for this code.
class MainClass;
class MyClass
{
public:
MyClass();
void (MainClass::*functionPointer)();
void callback();
};
class MainClass
{
public:
...
3
votes
4
answers
174
views
Why can you use a function as an if-statement condition without calling it? [duplicate]
I was wondering why both versions of this code have no error:
#include <iostream>
bool check_number(int n) {
return n < 5;
}
int main() {
int number = 6;
// (1) prints "...
1
vote
2
answers
240
views
Is it really legal for K&R to write "PFI strcmp, numcmp;" where PFI is typedef'd as "int (*)(char *, char *)"?
In The C Programming Language (Kernighan and Ritchie, 2nd ed) on p147, the authors show a typedef declaration
typedef int (*PFI)(char *, char *);
(PFI stands for "pointer to function returning ...
-1
votes
2
answers
107
views
sizeof(pointer_to_a_function) vs sizeof (function_name)
Here is the program as text:
#include <stdio.h>
int f(int x){
return x+1;
}
int main() {
int (*p)(int) = f;
printf( "%d\n", sizeof(p) );
printf( "%d\n", ...