Chrusciki
Chrusciki

Reputation: 115

Identifier Enum is Undefined

Ok i see this is a fairly common problem, but i cannot find a question that is similar to my problem.

I keep getting problems with

identifier "Baserate" is undefined

I am defining this as

tim.h

#include "tim_api.h"
enum Baserate {
 Rate_62_5ns = 0x0,
 Rate_125ns = 0x1,  
 Rate_250ns = 0x2,  
 Rate_500ns = 0x3, 
 Rate_1us = 0x4,    
 Rate_2us = 0x5,    
 Rate_4us = 0x6,    
 Rate_8us = 0x7,    
 Rate_16us = 0x8
};

the problem is when i define the function it is used in

tim_api.h

extern void TIM_Set_Period_ns(int Timer_Select, Baserate Set_Baserate, int Period);  

this is when i am building an embedded c program but when i run this in a c consol app it works

void TIM_Enable(Baserate my_baserate, void (*callback_function)());
int _tmain(int argc, _TCHAR* argv[])
{
TIM_Enable(Rate_62_5ns,prnt0);  
while(1);
return 0;
}


void TIM_Enable(Baserate my_baserate,void (*callback_function)())
{
}

So my question is why does the same enum Baserate work in the console app but not in the embedded program.

Upvotes: 3

Views: 8961

Answers (2)

P45 Imminent
P45 Imminent

Reputation: 8591

In C you need to use typedef enum Baserate {/*your values here as before*/} Baserate;

That is one of the subtle differences between C and C++.

Upvotes: 10

OregonTrail
OregonTrail

Reputation: 9039

Without a typedef you need to declare a Baserate as follows

enum Baserate {
    Rate_62_5ns = 0x0,
    Rate_125ns = 0x1,  
    Rate_250ns = 0x2,  
    Rate_500ns = 0x3, 
    Rate_1us = 0x4,    
    Rate_2us = 0x5,    
    Rate_4us = 0x6,    
    Rate_8us = 0x7,    
    Rate_16us = 0x8
};

enum Baserate a_rate = 0x6;

With a typedef

typedef enum {
    Rate_62_5ns = 0x0,
    Rate_125ns = 0x1,  
    Rate_250ns = 0x2,  
    Rate_500ns = 0x3, 
    Rate_1us = 0x4,    
    Rate_2us = 0x5,    
    Rate_4us = 0x6,    
    Rate_8us = 0x7,    
    Rate_16us = 0x8
} Baserate;

Baserate a_rate = 0x06;

Upvotes: 4

Related Questions