Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

For loops in embeeded C

I am working on a problem, I have a variable and I have to use inside of for loops

for(i=0;i<y*2+1;i++)
{
.
.
.
}

if I use like that does the processor speed decrease? Is there any disadvantage?

does the processor speed decrease in embeeded C? Is there any disadvantage?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Readability and maintainability (and functional correctness, for obvious reasons) are always more important than any "advantage" you might get from changing one single for loop in your code.

Only optimize when necessary, not in advance! (there are heaps of people on StackOverflow that have said this before, for example: https://stackoverflow.com/a/325307/6266506)

Compilers already do a great job of optimizing code (for speed, for size, or whichever one you prefer). You really shouldn’t worry about one for loop.

Size is mostly influenced by linking extra source, libraries or big variables in memory.
Execution speed will almost never be determined by one single for loop statement.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading