All Questions

1809
votes
27answers
145282 views

Do I cast the result of malloc?

In this question, someone suggested in a comment that I should not cast the result of malloc, i.e. int *sieve = malloc(sizeof(int) * length); rather than: int *sieve = (int *) malloc(sizeof(int) *...
382
votes
5answers
154497 views

Why is “while ( !feof (file) )” always wrong?

I've seen people trying to read files like this in a lot of posts lately. #include <stdio.h> #include <stdlib.h> int main( int argc, char **argv ) { char * path = argc > 1 ? argv[...
650
votes
13answers
52395 views

Why are these constructs (using ++) undefined behavior?

int main(int argc, char ** argv) { int i = 0; i = i++ + ++i; printf("%d\n", i); // 3 i = 1; i = (i++); printf("%d\n", i); // 2 Should be 1, no ? volatile int u = 0; u = u++ +...
472
votes
19answers
241596 views

What should main() return in C and C++?

What is the correct (most efficient) way to define the main() function in C and C++ — int main() or void main() — and why? If int main() then return 1 or return 0? There are numerous duplicate...
401
votes
1answers
331202 views

The Definitive C Book Guide and List

This question attempts to collect a community-maintained list of quality books on the C programming language, targeted at various skill levels. C is a complex programming language that is difficult t...
389
votes
8answers
33613 views

Undefined, unspecified and implementation-defined behavior

What is the difference between undefined, unspecified, and implementation-defined behavior in C and C++?
604
votes
8answers
142235 views

What is the strict aliasing rule?

When asking about common undefined behavior in C, souls more enlightened than I referred to the strict aliasing rule. What are they talking about?
239
votes
7answers
30148 views

What is array decaying?

What is decaying of an array? Is there any relation to array pointers?
728
votes
14answers
494708 views

How do I use extern to share variables between source files?

I know that global variables in C sometimes have the extern keyword. What is an extern variable? What is the declaration like? What is its scope? This is related to sharing variables across source fi...
139
votes
11answers
85510 views

Why is the gets function so dangerous that it should not be used?

When I try to compile C code that uses the gets function, I get a warning: warning: the gets function is dangerous and should not be used. I remember this has something to do with stack protection an...

Previous Next