How to pass ENUM as function argument in C

That’s pretty much exactly how you do it:

#include <stdio.h>

typedef enum {
    NORMAL = 31414,
    EXTENDED
} CyclicPrefixType_t;

void func (CyclicPrefixType_t x) {
    printf ("%d\n", x);
}

int main (void) {
    CyclicPrefixType_t cpType = EXTENDED;
    func (cpType);
    return 0;
}

This outputs the value of EXTENDED (31415 in this case) as expected.

Leave a Comment