Questions tagged [libc]

The C standard library consists of a set of sections of the ISO C standard which describe a collection of headers and library routines used to implement common operations, such as input/output and string handling, in the C programming language.

The C standard library consists of a set of sections of the ISO C standard which describe a collection of headers and library routines used to implement common operations, such as input/output and string handling, in the C programming language.

There are many implementations of libc with different resource requirements, security goals, etc. With a typical tool chain the libc, compiler and OS work together to achieve some ISO, Posix or custom features/standards. Some libc implementation are only a subset of the ISO standard, but still full featured enough to be used in many applications.

Specific libc tags:

  • - the full Gnu Libc found on most GCC installs.
  • - a smaller micro-controller libc for resource constrained devices
  • - Android libc
  • - unhosted libc
  • - more modern lighter foot print libc

Websites

See also:

Do not confuse with , which is for the C++ programming language.

1076 questions
270
votes
17 answers

C read file line by line

I wrote this function to read a line from a file: const char *readLine(FILE *file) { if (file == NULL) { printf("Error: file pointer is null."); exit(1); } int maximumLineLength = 128; char *lineBuffer = (char…
lron
  • 2,717
  • 2
  • 16
  • 3
188
votes
7 answers

How can I link to a specific glibc version?

When I compile something on my Ubuntu Lucid 10.04 PC it gets linked against glibc. Lucid uses 2.11 of glibc. When I run this binary on another PC with an older glibc, the command fails saying there's no glibc 2.11... As far as I know glibc uses…
falstaff
  • 3,413
  • 2
  • 25
  • 26
162
votes
8 answers

stdlib and colored output in C

I am making a simple application which requires colored output. How can I make my output colored like emacs and bash do? I don't care about Windows, as my application is only for UNIX systems.
user142019
117
votes
6 answers

What's the difference between hard and soft floating point numbers?

When I compile C code with my cross toolchain, the linker prints pages of warnings saying that my executable uses hard floats but my libc uses soft floats. What's the difference?
Evan Kroske
  • 4,506
  • 12
  • 40
  • 59
111
votes
4 answers

Are types like uint32, int32, uint64, int64 defined in any stdlib header?

I often see source code using types like uint32, uint64 and I wonder if they should be defined by the programmer in the application code or if they are defined in a standard lib header. What's the best way to have these types on my application…
felipecrv
  • 1,780
  • 2
  • 15
  • 14
111
votes
7 answers

What is the rationale for fread/fwrite taking size and count as arguments?

We had a discussion here at work regarding why fread() and fwrite() take a size per member and count and return the number of members read/written rather than just taking a buffer and size. The only use for it we could come up with is if you want to…
David Holm
  • 17,522
  • 8
  • 47
  • 47
109
votes
5 answers

Is snprintf() ALWAYS null terminating?

Is snprintf always null terminating the destination buffer? In other words, is this sufficient: char dst[10]; snprintf(dst, sizeof (dst), "blah %s", somestr); or do you have to do like this, if somestr is long enough? char dst[10]; somestr[sizeof…
Prof. Falken
  • 24,226
  • 19
  • 100
  • 173
83
votes
4 answers

Linking against an old version of libc to provide greater application coverage

Linux binaries are usually dynamically linked to the core system library (libc). This keeps the memory footprint of the binary quite small but binaries which are dependent on the latest libraries will not run on older systems. Conversely, binaries…
Gearoid Murphy
  • 11,834
  • 17
  • 68
  • 86
83
votes
2 answers

Compiling without libc

I want to compile my C-code without the (g)libc. How can I deactivate it and which functions depend on it? I tried -nostdlib but it doesn't help: The code is compilable and runs, but I can still find the name of the libc in the hexdump of my…
u149796
  • 1,788
  • 4
  • 14
  • 19
81
votes
6 answers

Why is there no strtoi in stdlib.h?

I have grown accustomed to strtod and variants. I am wondering why there is no strtoi shipped with . Why is it that the integer type is left out of this party? Specifically I am asking why there is not a version of atoi with the safety…
Eli
  • 2,041
  • 4
  • 18
  • 20
75
votes
9 answers

Faster way to zero memory than with memset?

I learned that memset(ptr, 0, nbytes) is really fast, but is there a faster way (at least on x86)? I assume that memset uses mov, however when zeroing memory most compilers use xor as it's faster, correct? edit1: Wrong, as GregS pointed out that…
maep
  • 1,318
  • 1
  • 12
  • 15
73
votes
2 answers

How to use debug version of libc

Short version of question: How can I get gdb to use the debugging symbols for libc? Longer version: I am debugging a program with gdb and I want to see information about a futex used by libc. However, at some point during debugging I get output such…
Gabriel Southern
  • 9,602
  • 12
  • 56
  • 95
62
votes
0 answers

gcc: why is the -lm flag needed to link the math library?

I just discovered that the -lm flag is needed by gcc in order to compile a program that refers a function from the math library. I'm wondering why an explicit linking flag isn't needed when compiling programs containing other libraries such as the…
matteoamc
  • 651
  • 1
  • 7
  • 5
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
58
votes
3 answers

Where is ptrdiff_t defined in C?

Where is ptrdiff_t defined in C?
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
1
2 3
71 72