How do you organize code in embedded projects?

前端 未结 6 568
迷失自我
迷失自我 2021-02-01 23:04

Highly embedded (limited code and ram size) projects pose unique challenges for code organization.

I have seen quite a few projects with no organization at all. (Mostly

6条回答
  •  遥遥无期
    2021-02-01 23:46

    Although it is a bit painful, one organization technique that is somewhat common with embedded C libraries is to split every single function and variable into a separate C source file, and then aggregate the resulting collection of O files into a library file.

    The motivation for doing this is that for most normal linkers the unit of linkage is an object, for every object you either get the whole object or none of it. Since there is a 1-1 relationship between C files and object files, putting each symbol in it's own C file gives each one it's own object. This in turn lets the linker pull in only that subset of functions and variables that are actually used.

    This sort of game doesn't help at all for headers they can happily be left as single files.

提交回复
热议问题