I've started learning about embedded systems and wondering since the compilers used for embedded applications aren't the same as the ones used for desktop applications; whether they behave differently in terms of how they compile the C code, files created, etc.
-
2\$\begingroup\$ is there really such a thing as an embedded C compiler? \$\endgroup\$– jsotolaCommented Jul 10, 2021 at 4:09
-
1\$\begingroup\$ @jsotola Well, I suppose there are C compilers (or IDEs rather) set up for embedded platforms. \$\endgroup\$– DKNguyenCommented Jul 10, 2021 at 4:34
-
4\$\begingroup\$ @jsotola Yes, there are indeed embedded C compilers. Lattice, Intel, and even Borland made one (their last edition was called the 'summer edition'.) The linker tools were different and they often included a few other tools to help along. 'crt0' was almost certainly different, as often were their libraries. Special, non-standard language keywords were also often included. You are just seeing things from a day when a lot of people are using fancy MCUs that barely make them any different from a workstation. Then the differences fade a bit. Embedded programmers have special skills beyond the norm. \$\endgroup\$– jonkCommented Jul 10, 2021 at 4:38
-
2\$\begingroup\$ Often, not always, they are cross-compilers (they run on different hardware than what they emit code for). There may also be deviations from standards or extensions for various reasons. It would help to know what you are considering as "embedded", the range is quite large, from MCUs with a few hundred bytes of program memory to machines more capable than most desktop PCs. \$\endgroup\$– Spehro 'speff' PefhanyCommented Jul 10, 2021 at 4:58
-
1\$\begingroup\$ They are pretty much the same. \$\endgroup\$– user57037Commented Jul 10, 2021 at 7:25
1 Answer
If we look at gcc that is targetted to the ARM platform ( as there are builds for ‘bare metal’ and Linux) the main differences is the runtime environment. In the bare metal build (arm-none-eabi) the C runtime has to provide the startup code to setup the interrupt vectors, stack, heap etc. as well,the C library has to take care of the low level details itself like memory allocation. Contrast this with a Linux build where the startup code doesn’t need to worry about the interrupt vectors (the o/s takes care of this), the stack and memory space is managed by the o/s. The C library can call the o/s for things like i/o and memory allocation.
Another thing that comes to mind is embedded systems frequently have the code in rom, so the startup code has to manage copying initialised data etc. into ram. Whereas under Linux, the assumption is the code is running in ram.
In summary, the compiler in itself is the same, the runtime environment is where it differs.