unions Questions
2
Let's suppose you are writing a C struct which represents a course in a meal. One of the fields in the course struct is of type:
enum TP_course {STARTER, MAINCOURSE, DESSERT};
Then, depending on...
1
Solved
I have 10 tables that i want 'union'. Here my table name with same fields.
sell_2007
sell_2008
sell_2009
...
sell_2015
sell_2016
In the example given by laravel do union in the two tables only (...
Charry asked 6/3, 2017 at 2:41
2
Solved
In C++11, I have the following union:
union SomeData
{
std::uint8_t Byte;
std::uint16_t Word;
std::uint32_t DWord;
unsigned char String[128];
};
If I initialize the union thusly;
SomeData d...
Magnification asked 1/3, 2017 at 14:56
3
Solved
How should I zero out an anonymous union? I couldn't find anything on cppreference page about it. Would memseting it's largest member with 0 work here?
For example -
#include <iostream>
#in...
Convertible asked 21/2, 2017 at 7:59
2
Solved
The C standard mandates that all pointers to unions have the same representation and alignment requirements.
It mandates the same for all pointers to structs.
Thus my question:
Why does the standar...
Huckaby asked 19/6, 2014 at 18:17
1
Solved
Given these structures:
typedef struct {
//[...]
} StructA;
typedef struct {
StructA a;
//[...]
} StructB;
typedef union {
StructA a;
StructB b;
} Union;
Are the two access methods below ...
2
Solved
Consider the following snippet:
#include <iostream>
union U{
U(): i(1) {}
int i;
int j = 2; // this default member initializer is ignored by the compiler
};
U u;
int main(){
std::cout ...
Accentor asked 16/11, 2016 at 13:21
2
Solved
I want to access shared ptr, which is in union, though segmentation fault happens:
struct union_tmp
{
union_tmp()
{}
~union_tmp()
{}
union
{
int a;
std::shared_ptr<std::vector<int>...
Used asked 28/10, 2016 at 9:24
3
Solved
C++11 allowed the use of standard layout types in a union: Member of Union has User-Defined Constructor
My question then is: Am I guaranteed the custom destructor will be called, when the union go...
Kaifeng asked 18/10, 2016 at 11:24
1
Solved
For the following code:
class Foo{
int foo;
public:
Foo() : foo(13) {}
int getFoo() const { return foo; }
};
union Bar{
Foo fBar;
double dBar;
};
I believe this is fully legal in C++. http...
Vassell asked 17/10, 2016 at 13:55
8
Solved
What is the sizeof the union in C/C++? Is it the sizeof the largest datatype inside it? If so, how does the compiler calculate how to move the stack pointer if one of the smaller datatype of the un...
0
I have code that fails to compile with Visual Studio 2015 Community Edition with the following error:
fatal error C1002: compiler is out of heap space in pass 2
The Code
struct Int { int i; }...
Kandykane asked 5/9, 2016 at 0:14
2
Solved
I have the following series of structs.
struct FooWord1
{
unsigned int Fill : 8;
unsigned int someData1 : 18;
unsigned int someData2 : 6;
};
struct FooWord2
{
unsigned int Fill : 8;
union
{...
Lucilelucilia asked 1/9, 2016 at 16:18
1
Assuming I have a union like this
union buffer {
struct { T* data; int count; int capacity; };
struct { void* data; int count; int capacity; } __type_erased;
};
Will I get into trouble if I mi...
Tideway asked 19/7, 2016 at 7:36
3
Solved
I am looking for an alternative to C-style union. boost::variant is one such option. Is there anything in std C++ ?
union {
int i;
double d;
}
Widely asked 22/3, 2012 at 22:0
3
Solved
I gather unrestricted unions as one of the functionality being put forth in C++11. Can anyone please explain the semantics behind this and the advantages it provides?
3
Solved
I am trying to make a vector that can hold string and int.
I've tried the code below, but I get the compilation error
error: use of deleted function 'my_union::~my_union()'
What am I doing w...
5
Solved
This code prints different values after compiling with -O1 and -O2 (both gcc and clang):
#include <stdio.h>
static void check (int *h, long *k)
{
*h = 5;
*k = 6;
printf("%d\n", *h);
}
u...
Khadijahkhai asked 6/4, 2014 at 16:52
2
I have a problem with misleading error messages, when I try to compile the following minimal sample in Visual Studio 2015:
class Vector
{
float x;
float y;
public:
Vector(float x, float y) : x...
Instillation asked 25/11, 2015 at 16:31
2
Solved
1
Solved
I'm trying to understand the use of union (the built in predicate) in Prolog. In many cases it seems to fail when it should succeed. It seems it has something to do with the order of the elements o...
Kicker asked 24/4, 2016 at 8:18
4
Solved
A number of answers for the Stack Overflow question Getting the IEEE Single-precision bits for a float suggest using a union structure for type punning (e.g.: turning the bits of a float into a uin...
Dissection asked 24/7, 2012 at 21:58
2
Solved
Given struct B, which inherits an anonymous union data member from struct A:
#include <cstddef>
struct A
{
union
{
struct { int a, b, c; };
int vals[3];
};
};
struct B: A
{
constexpr...
2
Suppose, for example, you want to implement a spreadsheet Cell in C++. A cell can be either a string, a number, or perhaps empty. Ignore other cases, like it being a formula.
In Haskell, you migh...
Quick asked 29/3, 2016 at 11:49
2
Solved
I have a function returning a union type. Is it allowed by the standard (C99) to access a field of a returned value directly from the call without copying the value to a variable. Here an exa...
© 2022 - 2024 — McMap. All rights reserved.