Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why not all the standard headers are preceded with std prefix?

Why not all the standard headers are preceded with std prefix? I.e. why complex.h and not stdcomplex.h?

like image 677
pmor Avatar asked Jan 25 '23 11:01

pmor


2 Answers

Why? why not? Who knows? The header files that make up the standard libraries began evolving into that category before a standard existed, over years of revisions by developers and scrutiny by C committee members. Many of the original authors and committee members who developed and canonized these files are now part of the big compiler in the sky and not available to answer the question "why" the standard naming convention is not really conventional or standard. But reading this wiki page on the topic may at least allow you to get a little history and context.

like image 128
ryyker Avatar answered Feb 15 '23 23:02

ryyker


The naming has historically nothing to do with formal ISO standardization and I don't think there ever was an ambition to toss std in front of everything standard library.

Earliest mention of a standard library seems to be K&R The C programming Language 1st edition from 1978, where below chapter 8.5 we can read:

The data structure that describes a file is contained in the file stdio.h, which must be included (by #include) in any source file that uses routines from the standard library.

Notably K&R refers to it as the standard library, not the standard input/output library. So maybe (and this is speculation) this header was originally intended to be the whole standard library for C. This is the only one of the current ISO standard library headers I can find mentioned in the book and it pre-dates formal standardization by more than ten years.

Then later during ANSI/ISO standardization the headers stdarg, stddef, stdio and stdlib were added to the first standard, but these are just 4 out of 15 standard headers using the std prefix. Various C or Unix de-facto standard headers just got added to the standard pretty much arbitrary. There was no sound rationale for anything, least of all API or naming. They just tossed in various already present "good to have" Unix libs into the standard.

Notably, the original C standard only guaranteed 6 unique letters for standard headers and all the original headers have names with 6 or less letters. This was expanded to 8 letters in C99.

C99 continued the tradition of arbitrary naming, adding a whole bunch of new headers, of which only stdint and stdbool have the std prefix. That C11 named most new headers with std prefix might be some influence from C++, but notably C11 also added uchar.h without prefix.

like image 44
Lundin Avatar answered Feb 16 '23 00:02

Lundin