首页 > 其他分享 >union

union

时间:2022-12-01 17:01:35浏览次数:31  
标签:typedef struct union TPack char include


/*************************************************************************
> File Name: helloC++.cpp
> Author: ma6174
> Mail: [email protected]
> Created Time: Fri 27 Jun 2014 10:36:49 PM WST -pthread
> Compile g++ -std=c++11 -g -o hello helloC++.cpp -pthread -lpthread
************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <iostream>
#include <map>
#include <list>
#include <thread>
#include <exception>
#include <future>
#include <chrono>
#include <condition_variable>
#include <mutex>
#include <memory>
using namespace std;
using namespace std::chrono;
inline bool IsLittleEndian()
{
static union
{
char ch[4];
unsigned long b;
}Test = {'1', '?', '?', '2'};
return '1' == (char)Test.b;

}
typedef struct T0
{
int a;
}T0;
typedef struct T1
{
char b;
}T1;
typedef union
{
T0 t0;
T1 t1;
}T;
typedef struct TPack
{
char type;
T t;
}TPack;
void fun()
{
TPack pack;
pack.type = '0';
pack.t.t0.a = 10;
}
int main()
{
cout << IsLittleEndian() << endl;


return 0;
}


标签:typedef,struct,union,TPack,char,include
From: https://blog.51cto.com/u_15899033/5902978

相关文章

  • sizeof(struct)和sizeof(union)的结果分析及其原因
    一个错误有的时候,在脑海中停顿了很久的“显而易见”的东西,其实根本上就是错误的。就拿下面的问题来看:structT{charch;inti;};使用sizeof(T),将得到什么样的答案呢......
  • Union-Find算法
    目录Union-Find算法简介思路代码实现应用应用1:Leetcode.130题目分析代码实现Union-Find算法简介UnionFind算法用于处理集合的合并和查询问题,它定义了两个用于并查集的......
  • 在实际应用中联合体union的妙用
        关键字union,又称为联合体、共用体,联合体的声明和结构体类似,但是它的行为方式又和结构体不同,这里的行为方式主要指的是其在内存中的体现,结构体中的成员每一个占......
  • C语言中union类型学习
    union指的是C语言的共用体(联合体)aunionisacontainerofoverlappingobject共用体它表示几个变量共用同一个内存位置,在不同的时间保存不同的数据类型和不同长度的......
  • [React Typescript] Discriminated unions in components props
    importReact,{useState}from"react";typeBase={id:string}|string;typeGenericSelectProps<TValue>={formatLabel:(value:TValue)=>string;......
  • CF48G Galaxy Union
    CF48GGalaxyUnion给定一棵基环树,求每个点到其他点的最小距离之和。\(n\leq2\times10^5\)。对于在环上的点和在树上的点分开处理。设在环上的点集为\(H\),先求出......
  • [Typescript] 110. Hard - Union to Tuple
    Implementatype, UnionToTuple,thatconvertsauniontoatuple.Asweknow,unionisanunorderedstructure,buttupleisanordered,whichimpliesthatwe......
  • 微信appid、openid、unionid的区别和关联
    来源:https://blog.csdn.net/qq_41990222/article/details/111587331applicationidentification(简称appid)是应用标识OpenID是一个以用户为中心的数字身份识别框架Un......
  • UnionID 机制说明
    如果开发者拥有多个移动应用、网站应用、和公众帐号(包括小程序),可通过UnionID来区分用户的唯一性,因为只要是同一个微信开放平台帐号下的移动应用、网站应用和公众帐号(包括......
  • 在实际应用中联合体union的妙用
    关键字union,又称为联合体、共用体,联合体的声明和结构体类似,但是它的行为方式又和结构体不同,这里的行为方式主要指的是其在内存中的体现,结构体中的成员每一个占据不同的内存......