Skip to main content
Stack Overflow
  1. About
  2. For Teams
Filter by
Sorted by
Tagged with
4 votes
2 answers
124 views

If we have similar structs (Base, Derived1 and Derived2) that both have a first element of type int: typedef struct stBase { int type; } Base; typedef struct stDerived1 { int type; // same ...
4 votes
3 answers
243 views

I'am verifying strict aliasing in C with the following code: #include <stdio.h> int main() { int x = 42; float *pf = (float *)&x; // strict aliasing violation //*pf = 3.14;...
4 votes
6 answers
215 views

I’m reading draft WG 14/N 3088, paragraph 6.5 Expressions, paragraph 7: 7 An object shall have its stored value accessed only by an lvalue expression that has one of the following types:98) — a type ...
2 votes
0 answers
227 views

I have code that has worked well when compiled with gcc but fails to work correctly when compiled with clang. I tracked down the issue to a read of volatile memory (on a microcontroller). I found by ...
Lee's user avatar
  • 51
5 votes
1 answer
243 views

How do strict aliasing rules apply to pointers-to-pointers-to-characters? For example, does the following contain undefined behavior? (godbolt) #include <iostream> #include <cstdlib> long ...
3 votes
3 answers
165 views

In the C norm, the following rule: C23 6.3.2.3 § 7 A pointer to an object type may be converted to a pointer to a different object type. If the resulting pointer is not correctly aligned for the ...
5 votes
3 answers
234 views

According to GCC's documentation and the various answers I read on Stack Overflow, it is allowed to use unions for type punning in C, like: union a_union { int i; double d; }; int f() { union ...
9 votes
1 answer
238 views

I was doing some reading on std::launder, and I thought of a scenario that the standard didn't seem to address. cppreference.com defines std::launder(T *p) like this: Formally, given the pointer p ...
1 vote
1 answer
151 views

C11 6.3.2.3p7 says: A pointer to an object type may be converted to a pointer to a different object type. If the resulting pointer is not correctly aligned 68) for the referenced type, the behavior ...
5 votes
4 answers
430 views

I have a set of structs that looks something like struct A { int x; int y; }; struct B { int x; int y; int z; }; struct Top { A a; B b; int* getPtr() { return &a.x; } }...
3 votes
2 answers
195 views

struct Node { Node *left; Node *right; int height; char data[]; }; This is how I used to define my data structure nodes, I find it very useful because I can embed the data directly in the ...
6 votes
1 answer
127 views

According to the C Standard: Each complex type has the same representation and alignment requirements as an array type containing exactly two elements of the corresponding real type; the first ...
3 votes
1 answer
142 views

I was reading this excellent material about the strict aliasing rule: https://stackoverflow.com/a/51228315/21691539 or https://gist.github.com/shafik/a956a17d00024b32b35634eeba1eb49e But in the ...
1 vote
1 answer
81 views

Does the following violate strict aliasing rule in C? #include <stdint.h> #include <stdio.h> #include <stdlib.h> int ialignment_of(double *p) { return (int)(((uintptr_t) p) % ...
3 votes
1 answer
178 views

It looks like in the following example the compiler assumes that the pointer to double passed to bar() may alias the integer member a: struct A { int a; double b; }; void bar(double*); int ...
Bikineev's user avatar
  • 1,777

15 30 50 per page
1
2 3 4 5
...
41

AltStyle によって変換されたページ (->オリジナル) /