Questions tagged [c]
For questions about the design of, or languages or features which are closely related to, C. Do keep in mind that C is related to but distinct from C++ (and there is no language called 'C/C++') and the appropriate tag should be used.
49 questions
3
votes
1
answer
473
views
How are C11 compilers calculating by how much to change the stack pointer before `goto` if the program uses variable-length arrays?
So, obviously, the C compiler, when compiling gotos, before inserting the jump instruction, needs to insert ...
11
votes
4
answers
6k
views
Why does the do-while loop in C-like languages require the curly brackets `{` and `}`? Wouldn't the grammar be perfectly parsable without them?
So, nearly all (or perhaps all) C-like languages require us to use curly brackets { and } when writing a do-while loop of more ...
0
votes
1
answer
152
views
Is it possible to apply # to a string literal resulting from another # in C?
In implementing the C preprocessor, I'm considering implementing the # operator not as converting the token sequence to a string literal, but to a special "...
-2
votes
2
answers
268
views
If this is the actual behavior of c preprocessor, then how should I interpret the standard if I were to implement it?
In the C standard, there's this:
A parameter in the replacement list, ..., is replaced by the corresponding argument after all macros contained therein have been expanded.
It's in Section 6.10.x.x, ...
10
votes
4
answers
3k
views
Is it plausible to let modulo-by-zero have a well-defined output value, provided that my language is C-like?
By mathematical definition, for every nonnegative integer n and every positive integer d, it holds that the modulo ...
4
votes
1
answer
271
views
How is the `wasm2c` tool from the WebAssembly Binary Toolkit capable of converting WebAssembly code doing unaligned access into C?
My AEC-to-WebAssembly compiler often outputs WebAssembly code doing unaligned access, which is valid in WebAssembly (it's just not guaranteed to be as fast as aligned access, and, on ARM, it usually ...
17
votes
4
answers
3k
views
Why did C99 have to add the underscored keywords for _Bool _Complex _Imaginary but not for inline or restrict?
C99 introduced the following keywords: _Bool _Complex _Imaginary ...
13
votes
2
answers
981
views
What optimizations are possible with unsequenced operators?
In C, most binary operators do not specify which operand will be evaluated first:
...
1
vote
1
answer
323
views
C specification's "sequenced before" and "pair-wise relation"
Paragraph 5.2.2.4 of ISO 9899:2024 says
Sequenced before is an asymmetric, transitive, pair-wise relation between evaluations executed by a single thread...
What does the pair-wise relation mean? Is ...
26
votes
3
answers
7k
views
Why do many programming languages use the symbol of two vertical parallel lines `||` to mean "or"?
Why do many programming languages use the symbol of two vertical parallel lines || to mean "or"? Is it because two switches connected in parallel form a ...
-1
votes
2
answers
541
views
If in computer science, compare-and-swap is known as "compare-and-swap," why are the C/C++ functions named atomic_compare_exchange_*?
In computer science, compare-and-swap is known as, well, "compare-and-swap" and often abbreviated as "CAS."
Why are the functions in the standard C library and C++ library named <...
19
votes
4
answers
3k
views
What's the justification for implicitly casting arrays to pointers (in the C language family)?
C has the behaviour of doing an implicit reference to element 0 of an array whenever you attempt to use it directly. This extends to passing arrays to/from functions - they get passed by pointer and ...
12
votes
0
answers
480
views
In C/C++, why does the logarithm of zero have a well-defined imaginary part?
By the C standard and the C++ standard:
$\log(0+0i) = -\infty+0 i$.
$\log(0-0i) = -\infty-0 i$.
$\log(-0+0i) = -\infty+\pi i$.
$\log(-0-0i) = -\infty-\pi i$.
However, if the floating-point complex ...
29
votes
5
answers
4k
views
Rationale for requiring struct prefix in C
In C, if you declare a struct like:
struct point {
int x, y;
};
you also have to use ...
4
votes
2
answers
418
views
Can software-based floating point implementations have any base?
The most common ones are base 2 or base 10 (aka decimal floating point). But can they have any base (like base 3, base 6, base 4 etc.)?