Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Enum type Warning in C

Status
Not open for further replies.

PrasadT1001

Newbie
Joined
Jul 14, 2011
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Mumbai, India
Activity points
1,301
I am writing a code on lpc1788 ARM Cortex M3. I came across a strange warning when I tried to configure the ports as GPIO. Despite of the warning, the code works absolutely fine, but to learn why this warning come, I am putting forward this post here. Following is the code that I have written.

static uint32_t * PIN_GetPointer(uint8_t portnum, uint8_t pinnum)
{
uint32_t *pPIN = NULL;
pPIN = (uint32_t *)(LPC_IOCON_BASE + ((portnum * 32 + pinnum)*sizeof(uint32_t)));
return pPIN;
}

void PINSEL_SetPinMode ( uint8_t portnum, uint8_t pinnum, PinSel_BasicMode modenum)
{
uint32_t *pPIN = NULL;
pPIN = PIN_GetPointer(portnum, pinnum);
*(uint32_t *)pPIN &= ~(3<<3); //Clear function bits
*(uint32_t *)pPIN |= (uint32_t)(modenum<<3);
}

int main(void)
{
PINSEL_SetPinMode(1,15,0); //this gave a warning: enumerated type mixed with another type
PINSEL_SetPinMode(1,18,PINSEL_BASICMODE_NPLU_NPDN); //this doesnt give any warning

/* Following is the enum present in a GPIO related header file, putting it here in comments so that
those who are going through this post, can see the enum

typedef enum
{
PINSEL_BASICMODE_NPLU_NPDN = 0, // Neither Pull up nor pull down
PINSEL_BASICMODE_PULLDOWN, // Pull-down enabled
PINSEL_BASICMODE_PULLUP, // Pull-up enabled (default)
PINSEL_BASICMODE_REPEATER // Repeater mode
}PinSel_BasicMode;
*/

return 0;
}
 

You have brought up the warning by specifying enum type for the formal parameter and supplying an integer literal. Although not all compilers will flag out a warning in this case, it seems reasonable, enforcing usage of enum constants rather than equivocal numbers. If you don't want it, specify a numeric type for modenum.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top