406,373
questions
10180
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. ...
3389
votes
12
answers
507k
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 ...
3160
votes
27
answers
1.7m
views
How to set, clear, and toggle a single bit
How can I set, clear, and toggle a bit?
3122
votes
30
answers
926k
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"
2807
votes
30
answers
396k
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 *) ...
2559
votes
4
answers
396k
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 ...
2163
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();
}
1840
votes
23
answers
753k
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 ...
1814
votes
20
answers
134k
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 ...
1810
votes
5
answers
204k
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 ...
1631
votes
23
answers
481k
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 ...
1514
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 ...
1434
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)?
1411
votes
22
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?