Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there a "c" prefix in the C++ version of C libs?

Tags:

c++

c

math.h -> cmath

stdlib.h -> cstdlib

I understand the difference between the ".h" version and the "c-prefix" version, but what was the reason to choose to use the "c" prefix?

like image 800
Fábio Diniz Avatar asked Mar 04 '11 17:03

Fábio Diniz


3 Answers

The name qualification is required to disambiguate between std-namespace-qualified versions of the C library headers and same-named C++ library headers. For example: "string.h" contains original C string functions, "cstring" contains std-qualified C string functions, and "string" contains C++ string classes. Without the name qualification, the latter two names would clash.

like image 167
Jollymorphic Avatar answered Nov 01 '22 19:11

Jollymorphic


The headers that end with .h are the original C headers. The ones with the c prefix (and no extension) are the C headers versions incorporated by the C++ Standard (the prefix "reminds" you that). In theory, everything inside them should be inside the std namespace.

like image 24
Leandro T. C. Melo Avatar answered Nov 01 '22 19:11

Leandro T. C. Melo


EDIT: Okay, we have some people who maybe didn't read the question carefully enough, or made assumptions on what the question meant or how answers were to be interpreted.

I'm answering the below question here:

but what was the reason to choose to use the "c" prefix?


To emphasize that it's originally from the C language, I presume.

like image 16
Platinum Azure Avatar answered Nov 01 '22 21:11

Platinum Azure