Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C Code is too heavily compiler dependent

I'm writing an OS that should run on a variety of SoCs (e.g: Xilinx Zync, Freescale QorIQ). My problem, not all of the provided IDEs (given by Xilinx, Freescale, etc.) provide the same libraries (standard C & POSIX libraries). For instance, the CodeWarrior IDE has the timespec structure, while Xilinx's doesn't. Also, sleep is implemented in some of the provided libs, but I have my own implementation.

I want my code to be independent of the compiler (some manufacturers provide more than one IDE and with a different compiler).

Any suggestions?

like image 466
Tal A. Avatar asked Dec 20 '22 14:12

Tal A.


2 Answers

My suggestion: Code to POSIX standards. Where the vendor library falls short of POSIX, implement a POSIX layer yourself.

Leave the core OS generally #ifdef-free, and put the mess in a conditionally-compiled compatibility layer.

like image 82
Jonathon Reinhart Avatar answered Dec 24 '22 01:12

Jonathon Reinhart


The simple (though longer-to-implement) solution is to not depend on the library provided by the vendor. Write your own library. Probably this can be done with a little bit of layering. All of them provide strlen(), for example.

like image 38
wallyk Avatar answered Dec 24 '22 01:12

wallyk