AnsweredAssumed Answered

LPCOpen: #define vs const usage

Question asked by karthik venkatesh on May 24, 2017
Latest reply on May 30, 2017 by Kerry Zhou



In LPCOpen for LPC812, I could find two conventions being following while returning value from a function.

For example, Chip_Clock_GetIntOscRate() function returns "SYSCTL_IRC_FREQ" which is defined as 12000000 using #define as shown below:


But in function Chip_Clock_GetMainOscRate(), "OscRateIn" is returned where OscRateInn is a const variable with value 12000000, as shown below.



I understand the difference between #define and const.

#define - does not allocate memory. Just a text replacment. Cannot be passed as pointer in the function argument.

const - allocates dedicated memory in Flash and the value cannot be changed. Address of this can be used as argument of a function.


But my question is, why cant NXP could have simple used #define OscRateIn  (12000000) instead of const uint32_t OscRateIn = 12000000 ?