Author Topic: Code completion problem with #define  (Read 1811 times)

Quiss

  • Guest
Code completion problem with #define
« on: November 04, 2011, 08:56:16 am »
Hi,

I've encountered a problem with the code below:

Code: [Select]
#define GPIOA_BaseAddress       0x5000
#define GPIOA ((GPIO_TypeDef *) GPIOA_BaseAddress)

typedef struct GPIO_struct
{
  vu8 ODR; /*!< Output Data Register */
  vu8 IDR; /*!< Input Data Register */
  vu8 DDR; /*!< Data Direction Register */
  vu8 CR1; /*!< Configuration Register 1 */
  vu8 CR2; /*!< Configuration Register 2 */
}
GPIO_TypeDef;

void main()
{
for(;;)
{
(*(GPIO_TypeDef *) GPIOA_BaseAddress)-> // at this point, i can see structure member list
GPIOA-> // no CC when i use #define
}
}

I'm using CB with default settings, am i missing something here? (CB: svn build rev 7550, OS: Windows 7 32 bit)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 4992
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion problem with #define
« Reply #1 on: November 04, 2011, 10:06:16 am »
That's because CC does not do macro expansion on every identifier. (This takes a lot of time, as it does not have a full preprocessor)
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.