My C compiler is not like your C compiler.

I have worked with a variety of C compilers at my day jobs over the years. Although they try to be “real” compilers, they often have limitations that would drive “real” C programmers crazy.

Like, one tool I used did not allow constant strings longer than 80 characters. The error it gave was unhelpful, but eventually support was able to figure out what was going on.

Imagine my surprise to find that this would simply not build:

char *msg = "123456789012345678901234567890123456789012345678901234567890123456789012345678901";

…but removing one character allowed it to build just fine.

Another compiler did not allow constants to be passed as arguments to a function. You could not do this:

strcpy (buffer, "Hello"); // This wouldn't work.

…and had to do this instead:

char *temp = "Hello";
strcpy (buffer, temp); // This is the way.

And that was just the start of it. In that world, the “const” keyword was basically off-limits to use as you might be used to using it. A function that is not supposed to mess with a buffer passed in might look like this:

void function (const char *buffer_ptr, size_t buffer_size)
{
    // stuff...
}

…but since you cannot pass const data into functions on that compiler, that code will not compile.

And if you are trying to use code between a modern system (like a PC) and this compiler, removing “const” then has the modern compiler — with strict warnings turned on — will issue warnings if you pass a “constant string” into that function because it removes that “const” protection since it is a “char *” instead of a “const char *”.

My career is fun. Let’s use say I use “#ifdef” more than most C programmers ever have to…

If you don’t have to deal with this type of stuff, I hope you appreciate that. Embedded programmers have to do so much more work with so much less resources to get something done ;-)

Until next time…

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.