I am trying to spare a few bytes of program size. I faced a problem which I cannot understand and I hope somebody will help.
Look at this empty sketch, pleas. It takes just 444 bytes:
void setup()
{
}
void loop()
{
}
However, this one – 1332 bytes already!
void f() {
Serial.println(1);
}
void setup()
{
}
void loop()
{
}
Why?
It is supposed that function f()
will be cut-off during the linkage stage. But it is not.
And what can I do to cut such things off, since they are not used in the code?
f()
, it's the fact you're now using theSerial
object, which is massive.f()
static
, as instatic void f() {
will give the compiler enough information to recognize early on thatf
is unused and prevent it from building dependencies forprintln
that it later has to work to figure out whether or not it can eliminate; this is not particularly Arduino related.