Making large constants in C source more readable?

后端 未结 8 915
遇见更好的自我
遇见更好的自我 2020-12-19 06:34

I\'m working on some code for a microprocessor.
It has a few large, critical constants.

#define F_CPU 16000000UL

In this case, this is the C

8条回答
  •  执念已碎
    2020-12-19 07:01

    One possibility is to write it like that:

    #define F_CPU (16 * 1000 * 1000)
    

    alternatively

    #define MHz (1000*1000)
    #define F_CPU (16 * MHz)
    

    Edit: The MHz(x) others suggested might be nicer

提交回复
热议问题