enumerated variables

General discussion on mikroC PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
rekinchin
Posts: 11
Joined: 19 Aug 2009 13:16

enumerated variables

#1 Post by rekinchin » 13 Jan 2010 18:19

Are these supported

Code: Select all

enum MMCSD_err
   {MMCSD_GOODEC = 0,
   MMCSD_IDLE = 0x01,
   MMCSD_ERASE_RESET = 0x02,
   MMCSD_ILLEGAL_CMD = 0x04,
   MMCSD_CRC_ERR = 0x08,
   MMCSD_ERASE_SEQ_ERR = 0x10,
   MMCSD_ADDR_ERR = 0x20,
   MMCSD_PARAM_ERR = 0x40,
   RESP_TIMEOUT = 0x80};

MMCSD_err mmcsd_init();

produced error ; expected, but 'mmcsd_int' found

Thanks Robert

User avatar
anikolic
mikroElektronika team
Posts: 1775
Joined: 17 Aug 2009 16:51
Location: Belgrade
Contact:

#2 Post by anikolic » 18 Jan 2010 15:08

Hi,
You cannot just use MMCSD_err in defining function return type, because MMCSD_err is just a tag for enum, and not a typedef name. So, compiler cannot resolve type by just looking at a tag, and you must either use following declaration:

Code: Select all

enum MMCSD_err mmcsd_init(){
  return MMCSD_ERASE_SEQ_ERR;
}
or you may define enum with typedef. Here's the working corrected code for what you were trying to achieve:

Code: Select all

enum MMCSD_err{
  MMCSD_GOODEC = 0,
  MMCSD_IDLE = 0x01,
  MMCSD_ERASE_RESET = 0x02,
  MMCSD_ILLEGAL_CMD = 0x04,
  MMCSD_CRC_ERR = 0x08,
  MMCSD_ERASE_SEQ_ERR = 0x10,
  MMCSD_ADDR_ERR = 0x20,
  MMCSD_PARAM_ERR = 0x40,
  RESP_TIMEOUT = 0x80
};

enum MMCSD_err mmcsd_init(){
  return MMCSD_ERASE_SEQ_ERR;
}

void main() {
  PORTB = mmcsd_init();
  asm nop;
}
Best regards,
Aleksandar
Web Department Manager

rekinchin
Posts: 11
Joined: 19 Aug 2009 13:16

Thanks

#3 Post by rekinchin » 18 Jan 2010 17:41

Think I must have got too used to a compiler that took a short cut. Plus the project is a big conversion from said compiler :)

Post Reply

Return to “mikroC PRO for dsPIC30/33 and PIC24 General”