All Questions
Tagged with function-pointers struct
147 questions
0
votes
1
answer
100
views
C struct pointers [duplicate]
#include <stdio.h>
#include <stdlib.h>
typedef struct node* Node;
struct node{
int a;
struct node* next;
};
void insertAtBeginning(Node head){
Node temp = malloc(sizeof(struct node));
...
2
votes
2
answers
111
views
What is the correct way to assign function to a function pointer of a structure member
Can anyone please help me with how to pass a function to a function pointer inside struct in C?
I have a function as below
typedef struct LOAD_DRV_DATA
{
uint8_t LoadDrvId;
uint8_t dataLength;
...
1
vote
3
answers
91
views
How to organise big array of structs with function references in it? [closed]
I am trying to make readable/maintanable file that contains big array of struct instances, which have function reference in it.
Example of application, where this can be used, is user line command ...
2
votes
4
answers
153
views
How to place a function pointer in a c struct whereas the input parameter of the function pointer is the struct itself (i.e. "this" pointer in c)
I am trying to use a function pointer inside a struct, whereas the function pointer needs an instance of the struct itself as argument. My current code snippet looks like this:
#include "stdio.h&...
3
votes
2
answers
152
views
What exactly happens when you typedef a function pointer b/c my test code works but I don't think it should? [duplicate]
I am learning C and C++. I wrote a program in C++ and I am writing the same program in C. I want to use structs in C to mimic the classes I wrote in C++. To this end, I wrote test code that (1) ...
1
vote
1
answer
98
views
Using a function pointer inside a struct [closed]
I am trying to use a struct as a function container, but I am unable to do so.
Here is my code for the struct aliased as methods
typedef struct {
void (*addAtHead)(LinkedList*,int);
...
0
votes
2
answers
96
views
C++ Calling pointer of a struct's function [duplicate]
I have a simple code as below:
int global1(int x)
{
return x * 5;
}
int global2(int x)
{
return x + 5;
}
struct some_struct {
int a;
int foo1(int x)
{
return x * a;
}
int foo2(int ...
0
votes
0
answers
25
views
I will write an eprom driver.This writing process will be based on address and size.Iwill write it in Clanguage
I have an eeprom that communicates via SPI. I will write a driver for this eeprom, but this writing process will not contain any ready-made functions. Writing and reading operations will start from a ...
5
votes
2
answers
314
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;
...
4
votes
2
answers
601
views
Access data member from function pointer in struct
I gotta admit. I lack experience with C and therefore I am unsure how to implement a function for a struct. There are plenty of answers out there: Define functions in structs, Can I define a function ...
0
votes
0
answers
85
views
Issue with vector of member function pointers within a struct [duplicate]
So I have a vector of a struct object containing a function pointer to an external class.
//Menu.h
#include "Byte.h"
struct menuItem
{
Byte (Byte::*funcPoint)(Byte&);
string ...
1
vote
1
answer
61
views
Function pointer and struct self inclusion [duplicate]
I need the following construct:
// Header file
typedef fc_t (*comdevCbackIsReady_t)(const comdev_t* const module);
typedef struct
{
comdevCbackIsReady_t cbIsReady;
} comdev_t;
This wont ...
1
vote
1
answer
48
views
Error initializing nested struct containing array of struct and function pointer c99 and gnu99
I am getting error during initialization of nested structure containing two members
unsigned int
typedef void (*vfptr)(void);.
The first structure or parent structure contains simply two variables ...
0
votes
1
answer
137
views
Difference between (function designator) and {function pointer}?
In clang, a pointer to a function and the designation/designator have distinct resulting grouping symbols, parenthesis compared to curly braces as seen in the code fragments further down.
What is:
...
0
votes
1
answer
44
views
how to store function pointers in array
typedef int (*t_built)(t_cmds *, t_table *);
struct cmdline
{
char * reserved[7]; /* "echo pwd cd unset export exit env" */
t_built builtin[7];
}
How can I store my builtin ...