L
L
list_get2015-07-10 09:29:32
Microcontrollers
list_get, 2015-07-10 09:29:32

How much MK is loaded when checking a long condition?

Good afternoon. Prompt whether it is effective to use one long condition? Or break it down into smaller pieces. MK freescale kinetis kl25 cortex - m0+
As an example (x1 >= n <= x2 && x3 > x4)

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Antony, 2015-07-10
@list_get

Arms (as well as, probably, all other processors) anyway cannot compare more than two numbers. In any case, this condition will be broken by the compiler into several.

S
Sasha, 2015-07-10
@massol

MK does not care, the compiler does this, it will break it.

V
veydlin, 2015-07-11
@veydlin

Sometimes you need to read textbooks on the programming language in which you write
. Previously, your question would have been relevant, with old compilers, but now the code

int I;
I = I + 1;
if(I < 5){ }

No different from your original entry like this:
int I;
if(++I < 5){ }

The compiler will bring everything under one.
I hope I answered your question x)

V
Vitaly Filinkov, 2015-07-10
@vitfil

Despite the fact that the compiler will break the condition into several comparisons, the calculations will be performed completely, because, EMNIP, there are no lazy evaluations in C. In your case, if the first condition is false, it makes no sense to calculate the second value, and therefore, you can break the condition into nested ifs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question