Search code examples
cembeddedstandardsmicrocontroller

Is there any C standard for microcontrollers?


Is there any special C standard for microcontrollers?

I ask because so far when I programmed something under Windows OS, it doesn't matter which compiler I used. If I had a compiler for C99, I knew what I could do with it.

But recently I started to program in C for microcontrollers, and I was shocked, that even it's still C in its basics, like loops, variables creation and so, there is some syntax type I have never seen in C for desktop computers. And furthermore, the syntax is changing from version to version. I use AVR-GCC compiler, and in previous versions, you used a function for port I/O, now you can handle a port like a variable in the new version.

What defines what functions and how to have them to be implemented into the compiler and still have it be called C?


Solution

  • Embedded systems are weird and sometimes have exceptions to "standard" C.

    From system to system you will have different ways to do things like declare interrupts, or define what variables live in different segments of memory, or run "intrinsics" (pseudo-functions that map directly to assembly code), or execute inline assembly code.

    But the basics of control flow (for/if/while/switch/case) and variable and function declarations should be the same across the board.

    and in previous versions, you used function for Port I/O, now you can handle Port like variable in new version.

    That's not part of the C language; that's part of a device support library. That's something each manufacturer will have to document.