Skip to main content
0 votes
1 answer
128 views

I'm trying to generate compile-time info about my POD types. Getting the offset of each member has been challenging due to limitations like no pointer conversions in constexpr, but I think I've found ...
Joshua Maiche's user avatar
12 votes
4 answers
2k views

I'm making a hashtable in C that I want to contain elements of different types, so I made it return a union that can hold int, float or char *. But when trying to print the union itself out, float ...
Daxxxmp4's user avatar
  • 123
7 votes
0 answers
213 views

I'm trying to make a union with a representation of an IEEE 32-bit floating point number. So far, I have this: #include <cstdint> struct FloatRepresentation{ union { float value; ...
8bitPixel's user avatar
0 votes
0 answers
95 views

I have a union declared in a class: class A { protected: union { uint16_t a[8] = { 0 }; uint64_t b[2]; }; } To test something in class A I created an extend class to ...
Tiger Hwang's user avatar
5 votes
1 answer
86 views

I have a program that maps device registers to unions of bitfields and integers. This is part of a larger code base, so although this is very C-style code, we are compiling it as C++20. Here is a ...
rmc's user avatar
  • 1,240
0 votes
0 answers
164 views

I know MultiArrayList supports tagged union, but it does it by converting it into struct containing untagged union and a tag field, effectively creating 2 ArrayList fields, one for union and the other ...
Krischal Khanal's user avatar
-2 votes
1 answer
69 views

In C++17 structured bindings, the object which is bound to cannot have anonymous unions. But in aggregate initialization, anonymous unions can exist in the aggregate being initialized, and the first ...
leekillough's user avatar
  • 1,117
1 vote
2 answers
170 views

Having read a fair bit about the purpose of unions, and type-punning (that it's basically not allowed, and you should rely on the compiler optimizing away memcpy calls), I'm wondering if the following ...
Vince W.'s user avatar
  • 3,849
3 votes
3 answers
321 views

I have a C codebase which uses unions for type punning. I am then unit testing this code in C++ with gmock. I know union-based type punning is illegal in C++, so wanted to make sure my usage is safe: /...
Dominik Kaszewski's user avatar
1 vote
0 answers
159 views

I link to the Jolt Physics library, and I can build my project no problems on Desktop. On Android I can install on my physical device through USB and debug it, and this error doesn't happen. However ...
Zebrafish's user avatar
  • 16.3k
17 votes
1 answer
723 views

Given a union that contains const char* and char* members, can data set through the char* be safely accessed through the const char*, in C99 and newer versions? For example, does the following have ...
Eli Minkoff's user avatar
0 votes
1 answer
76 views

I have a base class A, and two subclasses B and C which inherit from A. I would like to be able to store a union of B and C in an std::vector<A*>, but it seems that it may not be possible. Here'...
ERSUCC's user avatar
  • 70
-2 votes
1 answer
127 views

I am writing a simplified version of std::move_only_function in C++11. In my implementation, I provide Small Object Optimization (a.k.a SOO) for my code, which is basically a union that stores both a ...
Konvt's user avatar
  • 124
2 votes
1 answer
121 views

I have a union of a double and a struct of bit fields: union byte_real { double db; struct { unsigned long long int mant : 52; unsigned int exp : 11; unsigned int sgn : ...
CodeGeneratorMKM's user avatar
1 vote
2 answers
106 views

In the C standard (specifically, n3220, ie. the latest working draft of C23), which paragraphs would make the following code examples invoke undefined behaviour?: void f(int *a, char *b) { (*a)++; ...
ThomasP66's user avatar

15 30 50 per page
1
2 3 4 5
115