Questions tagged [c]
C is a general-purpose programming language used for system programming (OS and embedded), libraries, games, and cross-platform. This tag should be used with general questions concerning the C language, as defined in the ISO 9899 standard (the latest version, 9899:2018, unless otherwise specified — also tag version-specific requests with c89, c99, c11, etc.). C is distinct from C++, and it should not be combined with the C++ tag without a specific reason.
405,628
questions
10169
votes
26
answers
1.0m
views
What is the '-->' operator in C/C++?
After reading Hidden Features and Dark Corners of C++/STL on comp.lang.c++.moderated, I was completely surprised that the following snippet compiled and worked in both Visual Studio 2008 and G++ 4.4. ...
3383
votes
12
answers
503k
views
Improve INSERT-per-second performance of SQLite
Optimizing SQLite is tricky. Bulk-insert performance of a C application can vary from 85 inserts per second to over 96,000 inserts per second!
Background: We are using SQLite as part of a desktop ...
3153
votes
27
answers
1.7m
views
How to set, clear, and toggle a single bit
How can I set, clear, and toggle a bit?
3112
votes
30
answers
918k
views
What is the difference between #include <filename> and #include "filename"?
What is the difference between using angle brackets and quotes in an include directive?
#include <filename>
#include "filename"
2798
votes
30
answers
393k
views
Should I cast the result of malloc (in C)?
In this question, someone suggested in a comment that I should not cast the result of malloc. i.e., I should do this:
int *sieve = malloc(sizeof(*sieve) * length);
rather than:
int *sieve = (int *) ...
2551
votes
4
answers
395k
views
What does the ??!??! operator do in C?
I saw a line of C that looked like this:
!ErrorHasOccured() ??!??! HandleError();
It compiled correctly and seems to run ok. It seems like it's checking if an error has occurred, and if it has, it ...
2159
votes
18
answers
1.3m
views
What is the effect of extern "C" in C++?
What exactly does putting extern "C" into C++ code do?
For example:
extern "C" {
void foo();
}
1831
votes
23
answers
745k
views
What is the difference between const int*, const int * const, and int * const?
I always mess up how to use const int *, const int * const, and int * const correctly. Is there a set of rules defining what you can and cannot do?
I want to know all the do's and all don'ts in terms ...
1811
votes
20
answers
133k
views
With arrays, why is it the case that a[5] == 5[a]?
As Joel points out in Stack Overflow podcast #34, in C Programming Language (aka: K & R), there is mention of this property of arrays in C: a[5] == 5[a]
Joel says that it's because of pointer ...
1809
votes
5
answers
203k
views
What is ':-!!' in C?
I bumped into this strange macro code in /usr/include/linux/kernel.h:
/* Force a compilation error if condition is true, but also produce a
result (of value 0 and type size_t), so the expression ...
1776
votes
15
answers
152k
views
Is < faster than <=?
Is if (a < 901) faster than if (a <= 900)?
Not exactly as in this simple example, but there are slight performance changes on loop complex code. I suppose this has to do something with generated ...
1628
votes
23
answers
443k
views
Compiling an application for use in highly radioactive environments
We are compiling an embedded C++ application that is deployed in a shielded device in an environment bombarded with ionizing radiation. We are using GCC and cross-compiling for ARM. When deployed, our ...
1509
votes
12
answers
1.0m
views
How do function pointers in C work?
I had some experience lately with function pointers in C.
So going on with the tradition of answering your own questions, I decided to make a small summary of the very basics, for those who need a ...
1427
votes
22
answers
1.2m
views
What does "static" mean in C?
I've seen the word static used in different places in C code; is this like a static function/class in C# (where the implementation is shared across objects)?
1409
votes
25
answers
3.3m
views
How do I determine the size of my array in C?
How do I determine the size of my array in C?
That is, the number of elements the array can hold?