-4

What is better idea: write library which will be used by others in C11 or C99? Is it good justification that many people rather use C99 in theis project than C11 or it's not true? And what is better for microcontrollers? I am not professional and I want to have good excuse to not use generic C11 :P Thank you for your help. I hope it's not 'silly' question.

Edison91
  • 25
  • 4
  • What features from C11 to you plan to use that would be incompatible with a C99 compiler? – chqrlie Jan 30 '16 at 13:32
  • If the reasoning really is "I want to have a good excuse for not using generic C11", this is not programming related in the first place. There *are* pros and cons to the answer "should I write a library in C99 or C11", but asking us to give you a technical argument for your personal preference is... fishy. – DevSolar Jan 30 '16 at 13:48

2 Answers2

7

Be conservative with libraries you write. The less features you assume, the more people can use your library. Many libraries are carefully written to assume nothing more than ANSI C so they can be used on a wide range of hardware. This especially applies to embedded systems where compilers are often outdated and not really standards compliant. Be conservative in what you do, be liberal in what you accept.

fuz
  • 88,405
  • 25
  • 200
  • 352
0

For embedded development, I would recommend you only use C89 compatible features as it is not uncommon to see microcontrollers that come with old development tools, incompatible with even C99.

For Windows development, a recent version of Visual Studio will support most of C99, and other compilers too, but older versions of Visual Studio are notoriously incompatible, so you should determine if your library targets programmers stuck with old environments or not.

For linux or MaxOS, C99 should be no problem. I doubt you really need anything C11 specific, and it could be risky to assume that your users will all have a C11 compliant compiler / library combination.

You only ask about C99 and C11, but are you sure you even need C99? Using only C89 (aka ANSI C) should still compile correctly with C99 and C11 as long as you do not use obsolete features.

chqrlie
  • 131,814
  • 10
  • 121
  • 189
  • The removal of "implicit int" and implicit function declarations alone is enough to justify C99/C11. That's some major safety hazards removed right there. – Lundin Feb 01 '16 at 15:52
  • @Lundin: I agree completely, compiling in strict C99 mode with most warnings enabled is a good way to detect and remove a lot of potential or real bugs, but this is not incompatible the backward compatibility, allowing the code to also be compiled in C89 mode. *implicit int* and *implicit functions declaration* are examples of what I mean to exclude when I write *as long as you do not use obsolete feature* – chqrlie Feb 01 '16 at 23:15