preprocessor-macros

Search IconIcon to open search

Source: samek-embedded

Manual definition of macros

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#define RCGCGPIO *((unsigned int *)0x400FE608U)

#define GPIOF_BASE 0x40025000u
#define GPIOF_DIR (*((unsigned int *)( GPIOF_BASE + 0x400U)))
#define GPIOF_DEN (*((unsigned int *)( GPIOF_BASE + 0x51CU)))

int main() {
	RCGCGPIO |= 0x20U;
	GPIODIR |= 0xEU;
	GPIOF_DEN |= 0xEU;
	...
}

Notes:

  • Macros can also be partial statements
  • Calculations within the macros don’t lead to runtime overheads

Header files

1
2
3
4
5
6
#include <stdint.h>
#include "lm4f120h5qr.h"

int main() {
	...
}