编译器总是在cpp中编译未使用的函数

Compiler always compiles unused function when in cpp

本文关键字:编译 未使用 函数 cpp 编译器      更新时间:2023-10-16

即使我不使用这个函数,如果函数是在cpp中实现的,它也总是使用4字节的ram(因为attachInterrupt())。如果我让它在.h中内联,它就不会编译任何

.h
// attach the interrupt function
void IRLbegin(const uint8_t interrupt);
.cpp
void IRLbegin(const uint8_t interrupt){
// attach the function that decodes the signals
attachInterrupt(interrupt, IRLinterrupt, CHANGE);
}

我该怎么办?把所有东西都写在.h中,我认为这不是一种好的编码风格。由于Arduino环境的原因,我无法更改优化设置。

一个简单调用另一个函数的函数在头中进行了精细内联。试试IDE的1.5.8版本,因为它有一个更新的编译器,通常会在我找到的.CPP中内联小函数。