Arduino Compiler question.

Hello, I'm implementing Leonardo based ahrs system and I ran into a strange issue with compiler generating a program that is too big.

This code takes 92% of flash space: /*Based on the Madgwick algorithm found at:See: http://www.x-io.co.uk/open-s - Pastebin.com

After replacing these lines:

for (i = 0; i < 500;i++)
{
gyro.read();
compass.read();

Smoothing(&compass.a.x, &smoothAccX);
Smoothing(&compass.a.y, &smoothAccY);
Smoothing(&compass.a.z, &smoothAccZ);

delay(3);
}

With this:

while (true)
{
for (i = 0; i < 500;i++)
{
  gyro.read();
  compass.read();

  Smoothing(&compass.a.x, &smoothAccX);
  Smoothing(&compass.a.y, &smoothAccY);
  Smoothing(&compass.a.z, &smoothAccZ);

  delay(3);
}
}

It only takes 83% of space! I don't know how it's possible that ADDING code reduces the required space by almost 10%, but it's clearly some kind of a bug. Are there any flags or other tricks I can do to further reduce the size? Because I think it's using way too much space for a simple program like this.

Because your while(true) loop doesn't have a break the compiler knows that the rest of the function will never be used so it can be optimized away.

Hahaha, never mind, now I got it.

piotrek:
Hahaha, never mind, now I got it.

quick change the title of the post....lol

Arduino Compiler is so stupid!

It's actually very clever. It doesn't generate code it knows will never be used.

@piotrek: Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the "Code" icon above the posting area. It is the first icon, with the symbol: </>