Questions tagged [c-standard-library]

The C standard library is the standard library for the C programming language, as specified in the ANSI C standard

The C standard library is the standard library for the C programming language, as specified in the ANSI C standard. It was developed at the same time as the C POSIX library, which is a superset of it. Since ANSI C was adopted by the International Organization for Standardization, the C standard library is also called the ISO C library.

The C standard library provides macros, type definitions, and functions for tasks like string handling, mathematical computations, input/output processing, memory allocation and several other operating system services.

113 questions
89
votes
3 answers

Difference between C standard library and C POSIX library

I'm a little confused by "C standard lib" and "C POSIX lib", because I found that, many header files defined in "C POSIX lib" are also part of "C standard lib". So, I assume that, "C standard lib" is a lib defined by ANSI C organization, and there…
Alcott
  • 17,905
  • 32
  • 116
  • 173
69
votes
8 answers

Why wasn't a specifier for `float` defined in `printf`?

It looks like it could have been, there are (at least in C99) length modifiers that can be applied to int: %hhd, %hd, %ld and %lld mean signed char, short, long and long long. There is even a length modifier applicable to double: %Lf means long…
skyking
  • 13,817
  • 1
  • 35
  • 57
66
votes
2 answers

Why do some built-in Python functions only have pass?

I wanted to see how a math.py function was implemented, but when I opened the file in PyCharm I found that all the functions are empty and there is a simple pass. For example: def ceil(x): # real signature unknown; restored from __doc__ """ …
edgarstack
  • 1,096
  • 1
  • 10
  • 18
62
votes
1 answer

Why isn't there int128_t?

A number of compilers provide 128-bit integer types, but none of the ones I've used provide the typedefs int128_t. Why? As far as I recall, the standard Reserves int128_t for this purpose Encourages implementations that provide such a type to…
user1084944
59
votes
5 answers

What does the first "c" stand for in "calloc"?

A student asked the question and I didn't know for sure. Guesses include: "counted", "clearing", "chunked", "complete", ... The standard library documentation doesn't say what it stands for and there aren't similarly named functions that would…
Raymond Hettinger
  • 216,523
  • 63
  • 388
  • 485
54
votes
6 answers

What's the meaning of "reserved for any use"?

NOTE: This is a c question, though I added c++ in case some C++ expert can provide a rationale or historical reason why C++ is using a different wording than C. In the C standard library specification, we have this normative text, C17 7.1.3…
Lundin
  • 195,001
  • 40
  • 254
  • 396
44
votes
4 answers

what is difference between fgetpos/fsetpos and ftell/fseek

What's the difference between using the functions fgetpos() and fsetpos() and using the functions ftell() and fseek() to get and set a position in a file? What are fgetpos() and fsetpos() good for? Why would they be used instead of ftell() and…
carlfilips
  • 2,574
  • 3
  • 21
  • 27
43
votes
7 answers

Does the C standard guarantee buffers are not touched past their null terminator?

In the various cases that a buffer is provided to the standard library's many string functions, is it guaranteed that the buffer will not be modified beyond the null terminator? For example: char buffer[17] = "abcdefghijklmnop"; sscanf("123",…
Segmented
  • 795
  • 6
  • 13
31
votes
4 answers

Why does pow(n,2) return 24 when n=5, with my compiler and OS?

#include #include #include int main() { int n,i,ele; n=5; ele=pow(n,2); printf("%d",ele); return 0; } The output is 24. I'm using GNU/GCC in Code::Blocks. What is happening? I know the pow function…
exsnake
  • 1,767
  • 2
  • 23
  • 44
24
votes
4 answers

What is the difference between getch() and getchar()?

What is the exact difference between the getch and getchar functions?
bubble
  • 3,408
  • 5
  • 29
  • 51
21
votes
4 answers

What standard C library does Clang use? glibc, its own, or some other one?

I'm pretty sure glibc is the name of the standard C library implementation for gcc. But for LLVM/Clang I'm not sure. I've Googled to try to find if it comes with its own implementation of the whole standard C library, or whether they also use glibc.…
hippietrail
  • 15,848
  • 18
  • 99
  • 158
19
votes
9 answers

Why does fopen take a string as its second argument?

It has always struck me as strange that the C function fopen() takes a const char * as the second argument. I would think it would be easier to both read your code and implement the library if there were bit masks defined in stdio.h, like IO_READ…
Chris Cooper
  • 17,276
  • 9
  • 52
  • 70
18
votes
8 answers

Advantages of strncmp over strcmp?

Seems strncmp is usually recommended than strcmp, what are the advantages? I think it could be related to security. If this is the case, is it still applicable if one of the input string is known to be literal constant, like…
Thomson
  • 20,586
  • 28
  • 90
  • 134
16
votes
2 answers

why is abs() and fabs() defined in two different headers in C

The standard library function abs() is declared in stdlib.h, while fabs() is in math.h. Why are they reside in different headers?
Sanjana Jose
  • 238
  • 1
  • 8
13
votes
2 answers

"getenv... function ... may be unsafe" - really?

I'm using MSVC to compile some C code which uses standard-library functions, such as getenv(), sprintf and others, with /W3 set for warnings. I'm told by MSVC that: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
1
2 3 4 5 6 7 8