I sometimes see job listings for “embedded programmers,” but when I discover they are using an OS like Linux and a full file system, that does not quite seem “embedded” to me. I hardly consider a Raspberry Pi an “embedded” system. It is more like a desktop system that is small enough to embed.
See also: semantics, pedantic, and “pedantic a–holes” who love to comment about this stuff ;-)
But I digress.
Sometimes I find code in an open source project for an embedded target — such as an Arduino — that just screams “I don’t care about speed.” And, honestly, in most cases you really don’t. But why intentionally be slow?
I ran across a loop that searches for a target string in an index of strings. It was something like this:
int match (const char *name)
{
int index = -1; // Default to not found.
for (int idx = 0; idx < COUNT; idx++)
{
if (strncmp (array[idx], name, strlen (name)) == 0)
{
index = idx;
break;
}
}
return index;
}
The routine would accept a string and return the index of the first entry in an array that started with the same string. Here is a test program:
/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, OCaml, VB, Perl, Swift, Prolog, Javascript, Pascal, COBOL, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <stdio.h>
#include <string.h>
#define COUNT 8
const char *array[COUNT] =
{
"bacon",
"eggs",
"eggs and jam",
"sausage",
"pancakes",
"waffles",
"toast",
"coffee"
};
int match (const char *name)
{
int index = -1; // Default to not found.
for (int idx = 0; idx < COUNT; idx++)
{
if (strncmp (array[idx], name, strlen (name)) == 0)
{
index = idx;
break;
}
}
return index;
}
int main()
{
int index;
index = match ("foo");
printf ("found at: %d", index);
return 0;
}
If the search target is not found, it returns -1. If the search target matched, it returns the index in the array where the match was found.
I noticed there were no NULL checks and it relied on a #define rather than calculating the array size. This was probably done because the author knew their code was perfect and did not need error checking.
Or maybe they just wanted to save a few lines and some code space.
But the part that bugged me was this:
if (strncmp (array[idx], name, strlen (name)) == 0)
The use of strncmp() each time a compare was done seemed … inefficient. If you had a list of 1000 items, and where looking for a string that was 42 characters long, you would be calculating the length of that string 1000 times by starting at the first byte and moving forward until you found the NULL character at the end. The longer your search string, the slower the search would be.
In these modern times, we don’t really care about things like this. It also might be more important to save a few bytes of code space than use a new variable and pre-calculate the string length.
But when I used this code, I changed it to something like:
int match (const char *name)
{
int index = -1; // Default to not found.
size_t length = strlen(name);
for (int idx = 0; idx < COUNT; idx++)
{
if (strncmp (array[idx], name, length) == 0)
{
index = idx;
break;
}
}
return index;
}
I can sleep better now that I know I saved valuable microseconds… ;-)

Re the tangent on if a Pi is embedded or not:
I’d say that Pi1541 is truly embedded in that it runs directly on the hardware and does a cycle exact emulation of a Commodore 1541 disk drive, and not only cycle exact within the emulation but also as exact as possible as seen from the external I/O. I.E. it can run more games and demos than afaik any other 1541 emulation.