Jump to content

Talk:C standard library

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

A Commons file used on this page or its Wikidata item has been nominated for speedy deletion

[edit]

The following Wikimedia Commons file used on this page or its Wikidata item has been nominated for speedy deletion:

You can see the reason for deletion at the file description page linked above. —Community Tech bot (talk) 19:09, 18 August 2022 (UTC)[reply]

India Education Program course assignment

[edit]

This article was the subject of an educational assignment supported by Wikipedia Ambassadors through the India Education Program.

The above message was substituted from {{IEP assignment}} by PrimeBOT (talk) on 19:55, 1 February 2023 (UTC)[reply]

Alternate names

[edit]

WRT "The C standard library or libc": I think the term libc is rather *nix specific and therefore should not be implied to be such a common alternate name. IMO libc should be introduced later in the context of *nix implementations.

WRT "the C standard library is also called the ISO C library": IDK. I've never hear of that and google trends says it's very obscure: no history in US since 2004! A search on "ISO C library" does of course find this WP page, but this is a case of WP making a term notable ... which it's not supposed to do. Stevebroshar (talk) 17:20, 20 October 2024 (UTC)[reply]

The page discusses those library routines and macros that are specified by the ISO C standard. How that's done is platform-dependent. UN*Xes have traditionally provided a library, linked by default by the C compiler driver command (cc, gcc, clang, etc.), *usually* called "libc", as in "a file containing those routines has a name consisting of 'libc' followed by the appropriate extension, such as '.a' for a static library and '.so' (SunOS 4 and all systems using ELF), '.dylib' (macOS and other Apple OSes using Mach-O), '.sl' (32-bit HP-UX), or even '.a' (AIX) for a dynamically-linked shared library". However, it's called "libSystem" on Apple's OS.
On UN*Xes, that library also contains UN*X-specific APIs, such as open(), read(), write(), lseek(), close(), getpwuid(), etc.; perhaps that's why macOS (and NeXTSTEP?) renamed it "libSystem". On some UN*Xes, some UN*X APIs, e.g. socket APIs, may be in yet another library, not linked by default. I remember, at one point during the AT&T/Sun discussions about SVR4, AT&T made a proposal to break up libc into multiple libraries, including separating C language support routines and UN*X APIs, but that didn't happen.
On other platforms, there may be separate libraries for native OS APIs and standard C routines, although the "standard C routines" library may have additional routines, as is the case on Windows with Visual Studio.
So, yeah, at most it should speak of "libc" as being an idiom used on UN*Xes, rather than an alternate name.
As for the ISO standard, ISO/IEC 9899:2018 appears to refer to the "standard library" in some places, but that's about it. Guy Harris (talk) 18:04, 20 October 2024 (UTC)[reply]
I've changed it to say "The C standard library, sometimes referred to as libc, is the standard library for the C programming language,", and to ask for a citation on "sometimes referred to as libc", and also asked fo a citation on "ISO C library". Guy Harris (talk) 19:41, 20 October 2024 (UTC)[reply]
@Guy Harris i was thinking of axing both. 😁 I'm guessing those citations needed marks will be there years from now. 😂 Stevebroshar (talk) 23:43, 21 October 2024 (UTC)[reply]
@Guy Harris interesting. maybe the article should be titled "Standard library (C)" 🤔 Stevebroshar (talk) 23:34, 21 October 2024 (UTC)[reply]

ANSI/ISO...

[edit]

WRT "The C standard library ... is the standard library for the C programming language, as specified in the ISO C standard" That's not wrong, but it's overly specific and confuses the topic and reader. The ANSI C standard also defines a c standard lib. I think the intro should start with simply "The C standard library is the standard library for the C programming language". Later say that there have been multiple versions over time; first from ANSI, then later from ISO. IMO standardization is subordinate to what the library _is_. Stevebroshar (talk) 17:43, 20 October 2024 (UTC)[reply]

The ANSI C library was not interesting for very long, given that it transitioned to an ISO standard one year after it came out. It hasn't be "as specified in the ANSI C standard" since 1990.
IMO standardization is subordinate to what the library _is_. As per the title of the article, the library is "the standard library for the C programming language", and it became the standard library as a result of... standardization. Guy Harris (talk) 20:27, 20 October 2024 (UTC)[reply]
@Guy Harris oic. that's true. interesting that i didn't get that the 'standard' in the title was that related to the language standard. now that i read that it makes sense. needs better wording. Stevebroshar (talk) 23:30, 21 October 2024 (UTC)[reply]

What is __STDC_HOSTED__?

[edit]

WRT "According to the C standard the macro __STDC_HOSTED__ shall be defined to 1 if the implementation is hosted. A hosted implementation has all the headers specified by the C standard. An implementation can also be freestanding which means that these headers will not be present. If an implementation is freestanding, it shall define __STDC_HOSTED__ to 0."

What is that saying? If the value is 1, then the implementation (preprocessor? compiler? linker? toolset? app?) is hosted and that it (what ever it is) has all the c standard headers. If the value is 0, then it's freestanding which means it doesn't have all the headers. Freestanding means it has less than the full set? Really? That's confusing naming.

Whatever this macro actually does... I don't think it belongs in this article. Seems too technical for this context. Stevebroshar (talk) 17:51, 20 October 2024 (UTC)[reply]

What the standard says, as of C19, is:
5.1.2.1 Freestanding environment
In a freestanding environment (in which C program execution may take place without any benefit of an operating system), the name and type of the function called at program startup are implementation-defined. Any library facilities available to a freestanding program, other than the minimal set required by Clause 4, are implementation-defined.
The effect of program termination in a freestanding environment is implementation-defined.
5.1.2.2 Hosted environment
A hosted environment need not be provided, but shall conform to the following specifications if present.
5.1.2.2.1 Program startup
[The first function called is main(), and it gets handed an argument list.]
5.1.2.2.2 Program execution
In a hosted environment, a program may use all the functions, macros, type definitions, and objects described in the library clause (Clause 7).
5.1.2.2.3 Program termination
[If main() returns, it's just as if the program called exit() with the return value.]
As I remember, this was done to support both "C as a programming language atop an operating system" and "C as a programming language for writing code that might run directly on the hardware of an embedded system". For the latter, there's no guarantee that, for example, there's any of the I/O facilities, as your program might, for example, only have, as I/O devices, a couple of buttons, a couple of lights, and a voltage sensor - not much there to fprintf() to.
So:
If the value is 1, then the implementation (preprocessor? compiler? linker? toolset? app?) is hosted and that it (what ever it is) has all the c standard headers. Yes, and what the components of the implementation are is either implementation-defined or undefined, probably the latter. There may or may not be a preprocessor as a separate tool; there may be an interpreter rather than a compiler; there may be a run-and-go compiler and no linker; the toolset is whatever tools are supplied; there may not be an "app" in the sense of an IDE with a non-command-line user interface. And, yes, it has all the C standard headers, and makes available all of the C standard library routines.
If the value is 0, then it's freestanding which means it doesn't have all the headers. It is not guaranteed to have any of the headers other than the ones required by the standard to be present in freestanding implementations (in C18, that's <float.h>, <iso646.h>, <limits.h>, <stdalign.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, <stdint.h>, and <stdnoreturn.h>), and it is not guaranteed to have any of the library routines other than those specified by those headers. The standard says, of C implementations, that "A conforming implementation may have extensions (including additional library functions), provided they do not alter the behavior of any strictly conforming program." - a footnote means that "do not alter..." includes not defining functions not specified in the standard, e.g. it can't define open(), as that might collide with a function in a srictly conforming program (which is why Visual Studio's UN*X-alike routines have names such as _open()).
Freestanding means it has less than the full set? Really? YA RLY. An embedded C implementation might, for example, have sprintf() to format a message to display on a display panel, but not have anything to which to do a printf() or fprintf().
That's confusing naming. I guess the idea is that a "hosted" implementation is "hosted" by, i.e. running on top of, an operating system, whereas a "freestanding" implementation might run on bare hardware, standing by itself with no host.
Whatever this macro actually does... I don't think it belongs in this article. The macro probably belongs in C (programming language), rather than here, as it pertains to C as a whole, not just the library. Hosted vs. freestanding also mainly belongs there, although it's worth mentioning here, as it governs which of the routines here are guaranteed to be available. Guy Harris (talk) 19:00, 20 October 2024 (UTC)[reply]
@Guy Harris i didn't think to guess that freestanding would be about bare metal apps. bare metal is a pretty common term but freestanding to a programmer is not. this article should mention bare metal to define what freestanding means.
...that's the part i didn't understand. everything else follows from that. ... i guess the "it" is the app. not a tool chain tool. Stevebroshar (talk) 23:12, 21 October 2024 (UTC)[reply]
@Stevebroshar no. the "it" must be the tool chain since its about whether headed files exist... and they only exist in the tool chain. Stevebroshar (talk) 23:16, 21 October 2024 (UTC)[reply]
@Stevebroshar it's not "it". the word is implementation. i was confused what implementation it was talking about. Stevebroshar (talk) 23:21, 21 October 2024 (UTC)[reply]