Hello,
As a first note, I have done a lot of board searching on topics such as: "array of functions" and so forth, but can't find a definite solution.
My question is this: is it possible to store 'pointer to characater's' inside an array of characters?
For an example:
Code:
typedef void (*fnptr)(void);
fnptr myFunc[3] = {func1, func2, func3};
This allows someone to store an array of functions. Though, I wanted something similar for character arrays:
Code:
#include <stdio.h>
#include <stdlib.h>
typedef char* (char_set);
int main() {
int i;
char *ptr, *pch, *p;
char_set data[3] = {ptr, pch, p};
for (i = 0; i < sizeof(data)/sizeof(data[0]); i++) {
data[i] = malloc(10 * sizeof *data[i]);
if (data[i] == NULL)
return 0;
free(data[i]);
data[i] = NULL;
}
return 0;
}
Even though it works with gcc, some other compilers I've tested it with seems to think otherwise. One compiler says:
'initializer must be constant'
GCC itself even says this if I turn -Wall and -pedantic on: 'warning: initializer element is not computable at load time'
Is there any standard way I can accomplish this?
- Stack Overflow