This chapter collects a variety of tips that might be useful to experienced embedded C developers looking to start writing Rust. It will especially highlight how things you might already be used to in C are different in Rust. In Rust there is no preprocessor, and so many of these use cases are addressed differently. In the rest of this section we cover various alternatives to using the preprocessor. The closest match to ifdef
How C++ Works: Understanding Compilation
How C++ Works: Understanding Compilation | Toptal
Exclude Unused Code and Data from the Executable
In compiler theory , dead code elimination also known as DCE , dead code removal , dead code stripping , or dead code strip is a compiler optimization to remove code which does not affect the program results. Removing such code has several benefits: it shrinks program size, an important consideration in some contexts, and it allows the running program to avoid executing irrelevant operations, which reduces its running time. It can also enable further optimizations by simplifying program structure.
It was designed in a way to be compatible with non-GNU implementations, and we've been using this for years in highly portable code with very good results. There is a good reason for this - see below. Gnu CC needs to use the -Wall compiler directive to enable this yes, there is a finer degree of warnings control available, but we are very big fans of max warnings anyway. One of the easiest attributes to use, this marks a variable as intentionally being possibly unused.