Tagged Questions
0
votes
1answer
47 views
C, pointer to function in struct, warning “assignment from incompatible pointer type”
I have a struct defined as follow:
typedef struct {
char (*behave) (int*);
} BEHAVIOURSTRUCT;
this struct is defined in a .h file and it is included in the .c file
There i have a global ...
5
votes
4answers
431 views
What good is a function pointer inside a struct in c?
I guess using a function pointer inside a struct has something to do with encapsulating a function within a structure...? If so, then how exactly is this achieved??
And what good does it bring to ...
1
vote
2answers
81 views
scope of struct pointers in functions
If i have the following in a function:
struct example *A=malloc(sizeof(struct example));
does the node/memory space created where A points to get destroyed after the function ends/leaves? Or does ...
4
votes
1answer
171 views
struct containing a function pointer with itself as a return type in C
Got the following data struct:
typedef struct
{
lamp *lamp;
unsigned char a;
unsigned char b;
unsigned char c;
unsigned char d;
unsigned char e;
void (*func)(struct event ...
1
vote
2answers
128 views
What is the conventional way to have C headers with struct function pointers?
What is the conventional way to have C header files and source with function pointers in structs?
For example; I've declared my struct in the header file and all functions and source code in the code ...
0
votes
1answer
116 views
Pointer scope and constructor creation for array of struct
Jist of question detailed below: Why do I get errors saying that studentList and indexPtr are not declared in this scope?
I wrote a program that was supposed to create an array of structures and ...
0
votes
2answers
154 views
Initializing an array of structs in C then dereference later
I'm trying to build a serial command interpreter, so I want to store my commands in an array. I want each command to have a name and a function pointer so that I can compare the command name to what I ...
0
votes
0answers
138 views
Struct type pointers
I am developing a simple GUI application to compute the hash sums of files. It uses CommonCrypto library for hash sum algorythms. Therefore, the code that I use to compute SHA1 or MD5 hashes, for ...
0
votes
1answer
49 views
Using a function of a struct results in segfault
I have a struct with two pointers to functions and some data. The functions are definition-wise the same, however they should perform different tasks (which is why they have different names in the ...
2
votes
3answers
260 views
Assign struct member function pointer to class function
I've had a look through all the similar questions, but this specific scenario doesn't seem to have come up.
I have a plugin system, where the plugin receives the address of a function to call ...
7
votes
4answers
323 views
I am not getting a warning when I import a void pointer to a struct that has a pointer to a function in a shared object
Yesterday I was doing some research on dynamic loading of shared objects and about getting pointers to functions.
I have been told many times that sharing pointers to functions through void pointers ...
3
votes
1answer
122 views
Haskell FFI: Function pointer inside a struct
Say I have this struct in C:
/* C */
struct foo {
char *name;
int (*links)(foo*);
/* ... */
};
If I have x :: Ptr Foo, how do I get a FunPtr to x's links, without
using castPtrToFunPtr? I ...
0
votes
4answers
290 views
What is the effect of casting a function pointer void?
So I'm trying to write a buffering library for the 64th time and I'm starting get into some pretty advanced stuff. Thought I'd ask for some proffesional input on this.
In my first header file I have ...
0
votes
2answers
159 views
C - Trouble passing structure pointers to function
When I compile this I get lots of errors saying each part of my struct is invalid, along the lines of:
sort.c:16: request for member 'last' in something not a structure or union
And for the cases ...
1
vote
2answers
192 views
Returning class pointer, when asked for struct pointer (C++)
I have a skeleton of a project I need to implement a Doubly Linked List (no using stl) and the way the class is implemented is to inherit all is methods from a struct like so:
struct IDoubleList {
...