I'm new to C and trying to create a variadic function that takes in void pointers. However, I'm getting some unexpected behavior that I don't really understand...
token.h
typedef struct {
int (*funcOne) (void*, ...);
...
} symbols_t;
main.c
typedef struct {
char* name;
} job_t;
int job_create(void* objPtr, ...) {
char* name;
int i = 0;
va_list args;
va_start(args, objPtr);
while(&objPtr[i]) {
void* arg = va_arg(args, void*);
if (arg == NULL) {
break;
}
printf("arg %u: %s\n\n", i, arg);
i++;
}
va_end(args);
return EXIT_SUCCESS;
}
int main(void) {
symbols_t symbolTable;
symbolTable.funcOne = *job_create;
job_t myJob;
// See output one
symbolTable.funcOne(&myJob, "hey1", "hey2", "hey3", "hey4", "hey5", "hey6", "hey7", "hey8);
// See output two
symbolTable.funcOne(&myJob, "hey1", "hey2");
// See output three
symbolTable.funcOne(&myJob, "hey1");
// See output four
symbolTable.funcOne(&myJob);
return EXIT_SUCCESS;
}
Output one:
Output two:
Output three:
Output four:
Any insight into what's happening here would be greatly appreciated!



