C Language

C is a general-purpose computer programming language used for operating systems, libraries, games and other high performance work. This tag should be used with general questions concerning the C language, as defined in the ISO 9899:2011 standard. If applicable, include a version-specific tag such as c99 or c90 for questions relating to older language standards. C is distinct from C++ and it should not be combined with the C++ tag absent a rational reason.

51 votes
4 answers
936 views
How can one see content of stack with GDB?

I am new to GDB, so I have some questions: How can I look at content of the stack? Example: to see content of

avatar
Benton
0 1 0 9
asked 07 September, 2021
57 votes
15 answers
1.1K views
Quickly find whether a value is present in a C array?

I have an embedded application with a time-critical ISR that needs to iterate through an array of size 256 (pr

avatar
Sydney
0 1 0 9
asked 07 September, 2021
60 votes
3 answers
2.7K views
Possible GCC bug when returning struct from a function

I believe I found a bug in GCC while implementing O'Neill's PCG PRNG. (Initial code on Godbolt'

avatar
Vi
0 1 0 9
asked 07 September, 2021
66 votes
13 answers
1.6K views
Can num++ be atomic for 'int num'?

In general, for int num, num++ (or ++num), as a read-modify-write operation, is not atomic. But I often see co

avatar
Forrest
0 1 0 9
asked 07 September, 2021
50 votes
3 answers
1.7K views
Why does GCC generate such radically different assembly for nearly the same C code?

While writing an optimized ftol function I found some very odd behaviour in GCC 4.6.1. Let me show you the cod

avatar
Eddie
0 1 0 9
asked 07 September, 2021
64 votes
21 answers
306 views
Is inline assembly language slower than native C++ code?

I tried to compare the performance of inline assembly language and C++ code, so I wrote a function that add tw

avatar
Rudolf
0 1 0 9
asked 07 September, 2021
66 votes
24 answers
1.3K views
Protecting executable from reverse engineering?

I've been contemplating how to protect my C/C++ code from disassembly and reverse engineering. Normally

avatar
Lashawna
0 1 0 9
asked 07 September, 2021
62 votes
5 answers
2.4K views
Why does GCC use multiplication by a strange number in implementing integer division?

I've been reading about div and mul assembly operations, and I decided to see them in action by writing a

avatar
Xavier
0 1 0 9
asked 07 September, 2021
53 votes
7 answers
1.4K views
What is exactly the base pointer and stack pointer? To what do they point?

Using this example coming from wikipedia, in which DrawSquare() calls DrawLine(), (Note that this diagram h

avatar
Jesenia
0 1 0 9
asked 07 September, 2021
49 votes
12 answers
1.3K views
Is 'switch' faster than 'if'?

Is a switch statement actually faster than an if statement? I ran the code below on Visual Studio 2010's

avatar
Renaldo
0 1 0 9
asked 07 September, 2021
48 votes
10 answers
1.6K views
Using GCC to produce readable assembly?

I was wondering how to use GCC on my C source file to dump a mnemonic version of the machine code so I could s

avatar
Jesenia
0 1 0 9
asked 07 September, 2021
55 votes
17 answers
1.4K views
How do you get assembler output from C/C++ source in gcc?

How does one do this? If I want to analyze how something is getting compiled, how would I get the emitted ass

avatar
Winford
0 1 0 9
asked 07 September, 2021
63 votes
6 answers
1.9K views
What is the behavior of integer division?

For example, int result; result = 125/100; or result = 43/100; Will result always be the floor of the

avatar
Hallie
0 1 0 9
asked 07 September, 2021
63 votes
22 answers
1.1K views
How does C compute sin() and other math functions?

I've been poring through .NET disassemblies and the GCC source code, but can't seem to find anywhere

avatar
Thurman
0 1 0 9
asked 07 September, 2021
56 votes
19 answers
569 views
The most efficient way to implement an integer based power function pow(int, int)

What is the most efficient way given to raise an integer to the power of another integer in C? // 2^3 pow(2,3

avatar
Stacia
0 1 0 9
asked 07 September, 2021
62 votes
11 answers
1.2K views
Fast ceiling of an integer division in C / C++

Given integer values x and y, C and C++ both return as the quotient q = x/y the floor of the floating point eq

avatar
Patsy
0 1 0 9
asked 07 September, 2021
58 votes
7 answers
1.9K views
Fastest way to determine if an integer is between two integers (inclusive) with known sets of values

Is there a faster way than x >= start && x <= end in C or C++ to test if an integer is between t

avatar
Stacia
0 1 0 9
asked 07 September, 2021
51 votes
21 answers
671 views
Is there a standard sign function (signum, sgn) in C/C++?

I want a function that returns -1 for negative numbers and +1 for positive numbers. http://en.wikipedia.org/wi

avatar
Dorinda
0 1 0 9
asked 07 September, 2021
56 votes
30 answers
723 views
Divide a number by 3 without using *, /, +, -, % operators

How would you divide a number by 3 without using *, /, +, -, %, operators? The number may be signed or unsig

avatar
Bryant
0 1 0 9
asked 07 September, 2021
62 votes
5 answers
1.3K views
Why does the C preprocessor interpret the word "linux" as the constant "1"?

Why does the C preprocessor in GCC interpret the word linux (small letters) as the constant 1? test.c: #incl

avatar
Kurtis
0 1 0 9
asked 07 September, 2021