I have looked up how to pass an enumeration in a function, but that method doesn’t work when both the function and enumeration are declared in a structure. Here is my code :
test_setup.h:
1 #ifndef TEST_SETUP_H_
2 #define TEST_SETUP_H_
3 #include <stdio.h>
4 #include <stdlib.h>
5
6
7 typedef struct _test_setup {
8
9 int *partner;
10 int *send_first;
11 double *results;
12
13 enum { CHIP_WIDE, NODE_WIDE, SYSTEM_WIDE } SomeMatches;
14 void match_partners(SomeMatches match);
15
16 } test_setup;
17
18 #endif
test_setup.c :
1 #include "../includes/test_setup.h"
2
3 void match_partners(SomeMatches match) {
4 if (match == CHIP_WIDE) {
5
6 }
7 else if (match == NODE_WIDE) {
8
9 }
10 else if (match == SYSTEM_WIDE) {
11
12 }
13 else {
14
15 }
16 }`
Error:
In file included from src/test_setup.c:1:
src/../includes/test_setup.h:14: error: expected ‘)’ before ‘match’
src/../includes/test_setup.h:16: warning: no semicolon at end of struct or union
src/test_setup.c:3: error: expected ‘)’ before ‘match’
make: *** [setup.o] Error 1
I have tried every combination of declaring an enumeration and using it in the function parameters, but nothing has worked. Any ideas would be much appreciated. I am compiling with mpicc (because the rest of the program uses MPI functions) but I have tried with GNU GCC and I get the same warnings/errors.
For C
If you truly want C, then you simply can’t do any of this.
For C++
Use the scope-resolution operator
::