unions Questions

3

Solved

I have declared a flexible array member in union, like this: #include <stdio.h> union ut { int i; int a[]; // flexible array member }; int main(void) { union ut s; return 0; } and co...
Darnelldarner asked 15/9, 2017 at 6:49

5

Solved

Ever since TypeScript introduced unions types, I wonder if there is any reason to declare an enum type. Consider the following enum type declaration: enum X { A, B, C } var x: X = X.A; and a simil...
Claudclauddetta asked 27/10, 2016 at 3:53

1

(I just realized I first need to solve a much more basic issue with copying unions: When a union object is copied, is a member subobject created?. Please see that other question first.) The implic...
Cofferdam asked 8/12, 2019 at 2:6

0

When another member of a union is accessed, the C++ standard used to be silent on what happens, but that was fixed to explain that member access to a union object was allowed for the purpose of ass...
Colliery asked 8/12, 2019 at 2:44

2

Solved

When I was reading seastar source code, I noticed that there is a union structure called tx_side which has only one member. Is this some hack to deal with a certain problem? FYI, I paste the tx_si...
Sussna asked 27/11, 2019 at 9:26

3

Solved

It seems unions can be templated in c++11, they are used for example in the reference implementation of std::optional. Was that possible before c++11 ?
Tiernan asked 23/12, 2013 at 12:27

0

The following code gives different compilation result with g++ 7.3 and clang++ 7.0, but to my knowledge all of copy constructor of S1, S2, S3 is deleted and none of the instantiation should success...
Ship asked 15/11, 2019 at 6:37

1

Solved

I have a function that returns a union, which the caller knows how to process. Is there an efficient 1-line way to return a union? What I do now: typedef union { int i; char *s; double d; } FunnyR...
Ibby asked 3/10, 2019 at 21:8

3

In the current version of the C++ standard draft, [basic.life]/1 states: The lifetime of an object or reference is a runtime property of the object or reference. A variable is said to have vacuous...
Coauthor asked 10/9, 2019 at 20:33

4

Solved

Consider this program: #include <stdio.h> union myUnion { int x; long double y; }; int main() { union myUnion a; a.x = 5; a.y = 3.2; printf("%d\n%.2Lf", a.x, a.y); return 0; } Out...
Beetlebrowed asked 20/9, 2019 at 17:53

4

Solved

I have two sets of datarows. They are each IEnumerable. I want to append/concatenate these two lists into one list. I'm sure this is doable. I don't want to do a for loop and noticed that there is ...
Opiumism asked 10/2, 2011 at 19:53

2

Solved

I'm not quite sure about standard quotes about memcpy and union trivial members. Consider the code: struct Test{ union { void(*function_p)(void*); void(*function_p_c)(const void*); }; Test(...
Luciferin asked 26/8, 2019 at 7:45

6

Solved

What if I have this: union{ vector<int> intVec ; vector<float> floatVec ; vector<double> doubleVec ; } ; Of course, I'll be using just one of the 3 vectors. But... what happ...
Brendonbrenk asked 12/4, 2009 at 8:47

1

Solved

Both libstdc++ (GNU) and libc++ (LLVM) implement std::optional value storage using a union and both of them include a dummy member. GNU implementation: using _Stored_type = remove_const_t<_Tp&...
Occidental asked 14/8, 2019 at 14:24

0

Specifically, I would like to be able to use polymorphism without heap allocation in an embedded context (thus without dynamic allocation). My concern here seems to be that accessing the base membe...
Unshackle asked 10/6, 2019 at 19:54

4

Solved

Consider the following two examples: 1. union test{ struct { int a; int b[]; }; }; int main(void){ union test test; test.a = 10; printf("test.b[0] = %d", test.b[0]); //prints 0, UB? } ...
Gault asked 5/6, 2019 at 14:7

3

I would like to get proper tuple type with proper type literals from an object in TS 3.1: interface Person { name: string, age: number } // $ExpectType ['name','age'] type ObjectKeysTuple = ToT...
Mesothelium asked 27/11, 2018 at 16:14

3

Solved

I am currently working on a project in which I am provided the following structre. My work is C++ but the project uses both C and C++. The same structure definition is used by both C and C++. type...
Arsenite asked 21/3, 2019 at 13:35

3

Solved

Is it legal to do a type-punning between an integer and an array of integers? Specific code: #include <nmmintrin.h> #include <stdint.h> union Uint128 { __uint128_t uu128; uint64_t ...
Disqualification asked 5/3, 2019 at 20:11

1

Solved

The typedef below is for the DIR register from the Atmel SAMD21 ARM MCU include file. Since the bit struct member and the reg member are both 32 bits, is there any difference between the two member...
Live asked 27/2, 2019 at 4:56

2

Solved

I have (re?)invented this approach to zero-cost properties with data member syntax. By this I mean that the user can write: some_struct.some_member = var; var = some_struct.some_member; and thes...
Kingly asked 10/2, 2019 at 13:55

1

Solved

This question is based on this Consider the following: struct Hdr { int type; }; struct A { Hdr h; }; union Big { Hdr h; A a; }; and suppose that for Big big we know that big.a is the active ...
Different asked 5/2, 2019 at 1:27

4

Solved

Prompted by this question: The C11 standard states that a pointer to a union can be converted to a pointer to each of its members. From Section 6.7.2.1p17: The size of a union is sufficient to ...
Singleminded asked 4/2, 2019 at 14:52

3

Solved

I am struggling with using unions. Why am I unable to pass the function pointer to where the union would be? Any help would be greatly appreciated. Edit: removed a typedef #include <stdio.h&gt...
Ecumenical asked 4/2, 2019 at 13:32

2

Solved

I have started today to program on a PIC16f88, and found that the header for its registers contains a union that only contains a struct: extern volatile unsigned char ANSEL __at(0x09B); typedef un...
Benignity asked 27/1, 2019 at 15:58

© 2022 - 2024 — McMap. All rights reserved.