-6

How one can include his/her own programming functions to standard C (ANSI C) library? And any one who is learning or working on C language able to use those functions anywhere anytime, no need of development in general.

Example : someone developed function named "FunFun()" and assume it does fantastic work for most programmers. so how anyone can access this "FunFun" function without developing and just including standard library?

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
Parth
  • 644
  • 4
  • 10
  • 1
    There's not *the* `C library`, anyone could write one and there's already a variety of those. And of course, writing your own C library, you can add in whatever extension you want, many vendors do. But if you just want to share some code you wrote, *write a* ***stand-alone*** *library*, that's what they're there for. –  Jun 12 '17 at 07:32
  • 1
    You need to download the source code of the C library, add your own functions in that, compile and create a library again and install and replace that library with the original C library present in the standard library path. – Gaurav Pathak Jun 12 '17 at 07:33
  • 1
    If you want your own `superGreatFunction()` be available in *any* standard C library, this would mean to update the [C standard](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf) (!!) so any implementor had to include it. Have fun trying that ;) –  Jun 12 '17 at 07:34
  • 3
    I'm voting to close this question as off-topic because you clearly realize it is off-topic — you wouldn't add the apologia at top and bottom if it were known to be on topic. – Jonathan Leffler Jun 12 '17 at 07:42
  • 1
    Note that `` is a header, not a library. You'd be foolhardy to try modifying the standard library on your machine. All else apart, your changes would be lost the next time the system is updated to fix security problems in the standard library. You could add your own library to an appropriate location (e.g. `/usr/local/lib`) for general use — and you'd put the relevant header in `/usr/local/include`. – Jonathan Leffler Jun 12 '17 at 07:44
  • 1
    The **standard** library is called like that because it is **standardised**. Which implies you cannot just add functions to it at will. Feel free to contact the C working group to add the specification of your function, but you cannot enforce a specific implementation. What's your problem providing the library as seperate, custom library like hundreds of other very useful libraries? – too honest for this site Jun 12 '17 at 08:15

2 Answers2

4

The sane way to approach it would be to develop a 3rd party library and make it available over the internet through open source, Github etc.

The GNU C dialect is one such example, which is a collection of non-standard compiler extensions used by the GCC compiler. One could join the GCC open source group and try to get the new function added there. It would still not be standard library C, but the GCC extensions are often an inspiration to the C standard and several of them (designated initializers, flexible array members, anonymous struct/union etc) have been adopted into the language itself with the C99 and C11 standards. One of the purposes for GNU C is actually to serve as an experimental playground where new languages features can be tried out live.

If you truly wish to add a new function to the actual C standard library, you would have to join the ISO working group and convince them that the function should be added to the language. Or alternatively find a member of the committee and convince them to speak in favour of the new function.

All this of course assuming you are a C programming veteran, or otherwise nobody will likely take you seriously.

Lundin
  • 195,001
  • 40
  • 254
  • 396
  • GNU C actually is not a library, but extensions to the C language itself. Somed of it are legacies now, as C99 (line comments, VLAs, FAMs, …) and C11 (atomics, …) provide portable ways for them. – too honest for this site Jun 12 '17 at 08:17
  • @Olaf No but the `-std=gnu11` compiler option causes non-standard functions to pop up in the standard headers, whereas `-std=c11 -pedantic-errors` strips away non-standard functions from them. – Lundin Jun 12 '17 at 08:26
  • gcc is actually a freestanding limplementation only. Except for the few mandatory headers (which provide mostly target abstractions/information), it does not provide the standard library at all. You are right for the glibc, but gcc can basically use other libraries (afaik this is the case on Windows with MinGW, isn't it?). – too honest for this site Jun 12 '17 at 08:35
3

Your question can't be answered because it's based on several wrong assumptions.

  • Things like stdlib.h are not libraries. They are header files intended to be included in your program. Including means the contents are literally pasted into your program at the point of inclusion before the actual compilation happens. They are typically used for declaring functions, types, global variables etc a library provides. The actual library is then linked against after compilation.

  • There's no such thing as the C library as well as there's no such thing as the C compiler. is a language that is specified in an open standard (if you're interested, here's the last draft of the latest standard version C11). There are many actual implementations and a complete implementation consists of at least a compiler and a standard library. You can of course implement your own standard library. It's a lot of work to have it really conform to the standard (you would have to implement printf() and scanf() correctly, for example). With your own standard library, you can also include your own extensions, but this would only mean people using your standard library (instead of e.g. glibc on a GNU system) could directly use them.

  • For having a function available on any implementation of C, it would be necessary to have the C Standard specify it. You won't get a new function in the standard without some very good reasoning.


So if you want to make your own function available to others, do what everyone does and just implement it in your own library. Users can download it, include its headers and link against it.

  • The C standard is not an open standard. To get access to it, you need to pay money to ISO or your national standard institute. The draft happens to be very similar to the final standard (I have access to both) but there is no guarantee of that. For example you shouldn't list a draft standard as a valid, formal source. – Lundin Jun 12 '17 at 07:58
  • @Lundin note that the term *open standard* isn't exactly specified and free-of-charge access to the document isn't necessarily a requirement. –  Jun 12 '17 at 08:03
  • Free or not, the rough definition of an open standard is something not controlled by a standard institute, but some other organization. If not, then all standards except internal company standards would be "open". – Lundin Jun 12 '17 at 08:06
  • @Lundin [See Wikipedia](https://en.wikipedia.org/wiki/Open_standard) for a variety of slightly different definitions. What you write is kind of a common mimimal denominator ;) –  Jun 12 '17 at 08:13
  • @Lundin - There are various definitions of "open standard", but none of them preclude being controlled by a standard institute. The definitions typically amount to the standards being "publicly available" (as distinct from "no charge") and "developed in a collaborative and consensus driven process". – Peter Jun 12 '17 at 08:15
  • So in other words, the term "open standard" is not standardized. Maybe we should gather a working group and create a standard for the term. And make it an open standard... :) – Lundin Jun 12 '17 at 08:28
  • @Lundin kind of ;) Best would be to avoid ambiguities, but given C is very widespread in use, not tied to a company, publically well-known and has *many many* implementations, I personally consider it an open standard. Oh, well ... –  Jun 12 '17 at 08:30