30 questions
2
votes
2
answers
177
views
Are unsynchronized writes to global variables UB if code does not read from them? [duplicate]
For the purpose of debugging, our project is sometimes using global volatile variables:
volatile struct {
uintptr_t last_read = 0;
uintptr_t last_write = 0;
size_t reads = 0;
size_t ...
1
vote
1
answer
74
views
What does the C specification mean with "overlap adjacent units" in the context of bitfields?
I'm struggling to understand this section on bitfields of the C language specification (6.7.2.1.11):
An implementation may allocate any addressable storage unit large enough to hold a bit-field. If
...
0
votes
1
answer
82
views
Computing indices in Fenwick tree/Binary Indexed Tree (BIT)
The Fenwick tree data structure requires a member function read. For a index idx, read must compute several indices idx[0], idx[1], idx[2], ..., idx[last]. Each idx[i] will be the value that results ...
0
votes
1
answer
234
views
Characteristics of bit-Fields in C++
Reading https://en.cppreference.com/w/cpp/language/bit_field, are the following conclusions correct?
whether adjacent bit-fields have no padding in between is implementation-defined (this reads ...
1
vote
1
answer
150
views
What is source references in MISRA C?
In the MISRA C document there are explanations about "Source References" and there is a table whose rows are:
Unspecified, Undefined, Implementation-defined, Locale-specific, MISRA ...
2
votes
1
answer
185
views
C - Is reading a _Bool after setting it with memset undefined, implementation defined?
In ISO standard C, my understanding is that there is nothing that actually nails down the the representation of a _Bool, but it does say:
"_Bool is large enough to hold the values 0 and 1"
&...
1
vote
1
answer
68
views
Conditional inclusion: numeric value for the character constants: within #if/#elif vs. without #if/#elif: why matching is implementation-defined?
Case A: C11, 6.6 Constant expressions, Semantics, 5:
If a floating expression is evaluated in the translation environment, the arithmetic range and precision shall be at least as great as if the ...
6
votes
4
answers
1k
views
Is signed integer overflow undefined behaviour or implementation defined?
#include <limits.h>
int main(){
int a = UINT_MAX;
return 0;
}
I this UB or implementation defined?
Links saying its UB
https://www.gnu.org/software/autoconf/manual/autoconf-2.63/html_node/...
32
votes
2
answers
2k
views
Indexing an `unsigned long` variable and printing the result
Yesterday, someone showed me this code:
#include <stdio.h>
int main(void)
{
unsigned long foo = 506097522914230528;
for (int i = 0; i < sizeof(unsigned long); ++i)
printf(&...
0
votes
0
answers
77
views
C11, 6.6.10: IB: other forms of constant expressions: additional conformance documentation is needed
Why it (seems that it) is a general practice for C compiler vendors to not provide to the end users an additional conformance documentation about implementation-defined behavior regarding «other forms ...
97
votes
6
answers
9k
views
Why is assigning a value to a bit field not giving the same value back?
I saw the below code in this Quora post:
#include <stdio.h>
struct mystruct { int enabled:1; };
int main()
{
struct mystruct s;
s.enabled = 1;
if(s.enabled == 1)
printf("Is enabled\n"...
3
votes
1
answer
115
views
Is it implementation defined which algorithms can accept a mutable lambda?
I found here that lambdas are captured by value. This means that if an algorithm internally uses a second algorithm which accepts the lambda by value, any mutable state of the lambda will not be ...
5
votes
1
answer
2k
views
Number of bits in a byte - C standard [duplicate]
Why is something as fundamental as the number of bits in a byte, been kept implementation-defined by C standard? Are there examples where this could be useful?
from C99 , 3.6 ( available here link)
...
476
votes
10
answers
108k
views
Why should I not #include <bits/stdc++.h>?
I posted a question with my code whose only #include directive was the following:
#include <bits/stdc++.h>
My teacher told me to do this, but in the comments section I was informed that I ...
141
votes
4
answers
126k
views
Is sizeof(bool) defined in the C++ language standard?
I can't find an answer in the standard documentation. Does the C++ language standard require sizeof(bool) to always be 1 (for 1 byte), or is this size implementation-defined?