News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

Code completion problem with #define

Started by Quiss, November 04, 2011, 08:56:16 AM

Previous topic - Next topic

Quiss

Hi,

I've encountered a problem with the code below:

#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)

ollydbg

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.