4

Wikipedia says that "Newlib is a C standard library implementation intended for use on embedded systems". OK, but where can I find the latest canon version of it? i.e the correct true complete version.

Also, what other libraries exist for C language? Could you give me the ISO numbers for them?

I am trying to understand what library types/versions exist for C language so I know what they mean when I come across them in the future.

I would expected C standard library to be called just C standard library but that is not used and these different names like newlib do not seem very easy to decipher.

quantum231
  • 2,420
  • 3
  • 31
  • 53
  • 3
    Newlib is *an* implementation of *the* standard library. – GSerg Jan 22 '17 at 21:14
  • 1
    "I come across them in the future", just use the implementation of your compiler is generally enough. – Stargateur Jan 22 '17 at 21:15
  • 3
    The C standard describes a set of functions that all conformant C compilers must provide. This is the "C standard library". The actual *implementation* of the library itself, and especially it's name, that doesn't really matter. If you have a library that implements the "C standard library" it is ***a*** C standard library. – Some programmer dude Jan 22 '17 at 21:15
  • I am dabbling into Nios II, it is a processor implemented into an FPGA. It has its own IDE. However, I have also done C programming on the desktop computer. (Yes I am not a programmer, just fiddling about). Therefore, I was trying to understand what variations of C standard library exist and what name they have and what files they contain with what functions. – quantum231 Jan 22 '17 at 21:17
  • @ Some programmer dude, what do you mean by implementation of the library? If the code is written in high level language (being C itself) then why do we need to have different implementations at all? – quantum231 Jan 22 '17 at 21:18
  • 1
    So this URL seems to be the location for downloading newlib https://sourceware.org/newlib/ and this article describes a bit about compiling it http://www.billgatliff.com/newlib.html as does this wiki http://wiki.osdev.org/Porting_Newlib – Richard Chambers Jan 22 '17 at 21:19
  • 1
    That's like asking, why must we have different implementations of a C compiler? Or indeed different programming languages? Small embedded platforms have different requirements than a full multi-gigahertz PC with several gigs of memory. There is no "one size fits all" solution. – Some programmer dude Jan 22 '17 at 21:20
  • We can just use different compiler for different processors to compile the same C code to run on different processors, why then need different implementations? Could you define the term "implementation" as its being used here? – quantum231 Jan 22 '17 at 21:23
  • The term "implementation" means just that, the implementation, the actual code. And how would a library like the GNU libc (the GNU *implementation* of the C standard library) fit on a computer with only a couple of megabytes (or even *kilo* bytes) of memory? The library itself is *way* larger than that. Or for an operating system it was not designed for? You *do* know that there are small computers everywhere that doesn't fit with the "PC" acronym? Different operating systems, different hardware (not only CPU) and many other things means different variants (implementations) of the library. – Some programmer dude Jan 22 '17 at 21:31
  • Yes, I understand that, I am dealing with exactly that, a processor with less than 1MB of RAM. Then my last question (hopefully) is that, do large libraries standard library implementations and the small standard library implementations, contain the same functions since they have to fulfill the same specifications? If so, then what causes the change in size? – quantum231 Jan 22 '17 at 21:34
  • @quantum231 The implementation is generally less complete, but usually the incomplete functions are rarely used, so it will seem similar. That causes the reduction in size. Additionally, many things present in an OS (like threads, files, etc) must be manually added through _stubs_ to newlib for them to work. –  Jan 22 '17 at 21:39
  • If the library should implement the C standard functions, then yes both libraries must contain *at least* those. They can also contain platform specific functions. Or other non-standard functions. And the size depends on the code, the *implementation*. A "big" library can might have other optimizations while a "small" library only focuses on the size. Many algorithms can be coded differently to be fast or small, but often not both. Different ways of doing tings, even if the end result is the same, results in different code and different sizes. – Some programmer dude Jan 22 '17 at 21:41

1 Answers1

3

It is one of many implementations of the standard C library. Here are some other implementations:

This is a fine comparison of 4 different implementations. It might be easier for you to understand why people create their own implementations: http://www.etalabs.net/compare_libcs.html

They differ in speed, compilation time, supported architectures, number of lines of code in the code base, compatibility with the standard, license and so on.

Python, for example, has various different implementations as well - see this answer: https://stackoverflow.com/a/17130986/4694621.

Community
  • 1
  • 1
Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
  • aha, hmmm could you briefly describe what is meant by implementation. Since we are writing the library implementation in C code, why need different implementations? We can just use different compiler for different processors to compile the same C code to run on different processors, why then need different implementations? A standard library would certainly have to meet all its requirements right? – quantum231 Jan 22 '17 at 21:21
  • @quantum231 For example, you are creating a product and you don't want to use any GPL code. In this case GNU libc is not an option for you. The second example might be coding a super secure app and you have to make sure on your own that the libc you're using is secure enough for you - in that case you might want to choose an implementation with a code base small enough to audit and review it before using it. – Mateusz Piotrowski Jan 22 '17 at 21:27
  • @quantum231 Look at the link I've posted: http://www.etalabs.net/compare_libcs.html. There is a table explaining the differences between 4 implementations. You can easily see what it is all about. – Mateusz Piotrowski Jan 22 '17 at 21:29
  • by the way, since GPL means something is free and open source, why would one not want to use it? I mean, if something saves time and money we would opt for it right? I am an electronic engineer by the way, not software engineer but am learning about Nios II softcore used in Altera FPGAs and the tool suite used with them. – quantum231 Jan 22 '17 at 21:36
  • 2
    @quantum231 In some cases, one might not want to release their software source code. In that case, the GPL is an enemy. –  Jan 22 '17 at 21:38
  • 1
    @quantum231 Mark is right. This is basically the reason why. Sometimes releasing your source code is not the best solution for your business model and it is what GPL obliges you to do. (Of course, the whole licensing is a lot more complex so I encourage you to read a little bit about it. It is really fascinating.) – Mateusz Piotrowski Jan 22 '17 at 21:39
  • 3
    @quantum231: The language standard specifies only the types and names that the library must provide (in the form of function prototypes), as well as their behaviour (in plain English). It does not itself provide any code that implements this behaviour. The standard is not software, it is merely a specification. The actual libraries under discussion here are software. – Kerrek SB Jan 22 '17 at 21:49