Including typedef enum from header file in another header file

Evan Ohlsen

I keep running into an issue while trying to include an enumeration from one header file in antoher. The environment I am working in is embedded C using IAR Embedded Workbench.

I have a header file for dedicated enumerated types named "enums.h"

#ifndef ENUMS_H_
#define ENUMS_H_

typedef enum
{
    SET,
    SCHEDULE,
    EXECUTE
}action_type_t;

#endif

and a header file for a parser named "parser.h"

#ifndef PARSER_H_
#define PARSER_H_

#include "enums.h"
#include <stdint.h>

typedef struct
{
    action_type_t action;
    uint16_t nbytes;
}Message;

#endif

In parser.c I include the header as

#include "parser.h"

When I compile this, I get the error "identifier action_type_t is undefined"

What am I doing wrong here? I am stumped at this point.

Thank you

PSkocik

Your enum definition is missing commas, your parser.h uses uint16_t while having failed to include <stdint.h> and, to be extra pedantic, your include guard macro is encroaching on the reserved namespace because it starts with _ and a capital letter.

This should work:

enums.h:

#ifndef ENUMS_H_
#define ENUMS_H_

typedef enum
{
    SET,
    SCHEDULE,
    EXECUTE, /*the last comma is optional*/
}action_type_t;

#endif

parser.h:

#ifndef PARSER_H_
#define PARSER_H_

#include "enums.h"
#include <stdint.h>

typedef struct
{
    action_type_t action;
    uint16_t nbytes;
}Message;

#endif

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related