cancel
Showing results for 
Search instead for 
Did you mean: 

How to solve the Enum in struct build error

WhyIsThisSo
Associate III

Not sure what I am doing wrong here in my header file. I have a struct pump_info which has some enums as properties. I get a build error on all 3 on the enums in the struct.

Error

'operation_mode' does not name a type

'operation_mode' does not name a type

'operation_function' does not name a type

#ifndef PUMPINFO_H
#define PUMPINFO_H
 
#include "time.h"
 
enum pump_function {
	pump_function_off = 0, pump_function_manual = 1, pump_function_automatic = 2
};
 
enum operation_status {
	operation_status_off = 0, operation_status_on = 1
};
 
enum operation_mode {
	operation_mode_standby = 0, operation_mode_duty = 1
};
 
struct pump_info {
	pump_function pump1Function;
	operation_status pump1OperationStatus;
	operation_mode pump1OperationMode;
	float pump1Current;
	unsigned long pump1RunHours;
	tm pump1LastRunDateTime;
	pump_function pump2Function;
	operation_status pump2OperationStatus;
	operation_mode pump2OperationMode;
	float pump2Current;
	unsigned long pump2RunHours;
	tm pump2LastRunDateTime;
};
 
 
 
#endif // PUMPINFO_H

1 ACCEPTED SOLUTION

Accepted Solutions
Tilen MAJERLE
ST Employee

Your enums are not typedefed, so you need to use them with enum keyword.

struct pump_info {
	enum pump_function pump1Function;
	enum operation_status pump1OperationStatus;
	enum operation_mode pump1OperationMode;
        ....
};

 Or you can typedef them, and then use w/o enum keyword.

typedef enum pump_function {
	pump_function_off = 0, pump_function_manual = 1, pump_function_automatic = 2
} pump_function_t;
 
typedef enum operation_status {
	operation_status_off = 0, operation_status_on = 1
} operation_status_t;
 
enum operation_mode {
	operation_mode_standby = 0, operation_mode_duty = 1
} operation_mode_t;

 You then use them as

struct pump_info {
	pump_function_t pump1Function;
	operation_status_t pump1OperationStatus;
	operation_mode_t pump1OperationMode;
        ....
};

Your personal choice.

View solution in original post

3 REPLIES 3
Tilen MAJERLE
ST Employee

Your enums are not typedefed, so you need to use them with enum keyword.

struct pump_info {
	enum pump_function pump1Function;
	enum operation_status pump1OperationStatus;
	enum operation_mode pump1OperationMode;
        ....
};

 Or you can typedef them, and then use w/o enum keyword.

typedef enum pump_function {
	pump_function_off = 0, pump_function_manual = 1, pump_function_automatic = 2
} pump_function_t;
 
typedef enum operation_status {
	operation_status_off = 0, operation_status_on = 1
} operation_status_t;
 
enum operation_mode {
	operation_mode_standby = 0, operation_mode_duty = 1
} operation_mode_t;

 You then use them as

struct pump_info {
	pump_function_t pump1Function;
	operation_status_t pump1OperationStatus;
	operation_mode_t pump1OperationMode;
        ....
};

Your personal choice.

WhyIsThisSo
Associate III

@Tilen MAJERLE​ thanks heaps.

WhyIsThisSo
Associate III

Update:

typedef did not work, build warning error

warning: 'typedef' was ignored in this declaration

this worked

struct pump_info {
	enum pump_function pump1Function;
	enum operation_status pump1OperationStatus;
	enum operation_mode pump1OperationMode;
};