Python
Java
PHP
IOS
Android
Nodejs
JavaScript
Html5
Windows
Ubuntu
Linux
是否可以用 Rust 编写 Quake 的快速 InvSqrt() 函数?
这只是为了满足我自己的好奇心 是否有这样的实现 float InvSqrt float x float xhalf 0 5f x int i int x i 0x5f3759df i gt gt 1 x float i x x 1 5f x
Rust
floatingpoint
sqrt
typepunning
从实例驻留在固定格式(数据库、MMF)的基类派生...如何安全?
Note 我正在寻找有关正确搜索词的任何建议来阅读此类问题 对象关系映射 http en wikipedia org wiki Object relational mapping我想到了一个可以找到一些好的现有技术的地方 但我还没有看到任何
c
orm
C11
Wrapper
typepunning
类型双关:省略放置 new 和析构函数
已经有很多关于严格别名规则和类型双关的帖子 但我找不到我可以理解的关于对象数组的解释 我的目标是拥有一个内存池非模板类 用于存储对象数组 基本上我只需要在访问时知道实际类型 它可以被视为一个非模板向量 其迭代器将是模板 我想到的设计提出了几
c
placementnew
typepunning
是否允许类型相同但大小不同的双关数组?
类型相同但大小不同的双关数组仍然违反严格别名吗 int arr 4 int ref 2 reinterpret cast
c
Arrays
languagelawyer
typepunning
有符号到无符号整数的类型双关可以通过消除 >= 比较的需要来加快边界检查速度吗?
假设我的程序中有一个对性能非常关键的循环 我需要检查一个点是否在矩形内 但我知道在编译时下限始终为 0 如下所示 x gt 0 y gt 0 x lt width y lt height 我可以通过将 x 和 y 类型双关为无符号整数来消除
c
performance
int
integerarithmetic
typepunning
类型双关语与联盟成员访问
按照这个https stackoverflow com a 1812932 1814023 https stackoverflow com a 1812932 1814023 writing one member of union and
c
unions
typepunning
union '双关语'结构带有“公共初始序列”:为什么 C (99+) 而不是 C++ 规定了“联合类型的可见声明”?
背景 通过以下方式讨论类型双关的大多数非或实现定义的性质union通常引用以下位 此处通过 ecatmur https stackoverflow com a 31557852 2757035 https stackoverflow com
c
struct
unions
typepunning
gcc:如何正确使用 __attribute((__may_alias__)) 以避免“取消引用类型双关指针”警告
我有一些代码使用类型双关来避免调用成员 对象 的构造函数和析构函数 除非 直到实际上需要使用该对象 它工作正常 但在 g 4 4 3 下 我收到这个可怕的编译器警告 jaf jeremy desktop g O3 Wall puns cpp
c
gcc
compilerwarnings
strictaliasing
typepunning
为什么这种类型的双关不是未定义的行为?
这是一个我认为会调用未定义行为的玩具示例 include
c
undefinedbehavior
typepunning
编译时浮动打包/双关
我正在为 PIC32MX 编写 C 语言 使用 Microchip 的 PIC32 C 编译器 基于 GCC 3 4 进行编译 Added我遵循的标准是 GNU99 带有 GNU 扩展的 C99 编译器标志 std gnu99 我的问题是
c
gcc
Embedded
typepunning
使用“union”在整数和数组之间进行类型双关?
在整数和整数数组之间进行类型双关是否合法 具体代码 include
c
Arrays
unions
typepunning
std::bit_cast 和 std::start_lifetime_as 之间有什么有用的区别吗?
std bit cast显然是在 c 20 中引入的 和std start lifetime as被提议用于 c 23 来自P0593R5 https wg21 link p0593R5 由于它们似乎都要求所涉及的数据类型无论如何都是微不足
c
C20
cstandardlibrary
typepunning
bitcast
reinterpret_cast 类型双关实际上是未定义的行为吗?
这种类型的双关语似乎被广泛持有reinterpret cast以某种方式被禁止 正确地说 未定义的行为 即 本国际标准没有提出要求的行为 https timsong cpp github io cppwp n4659 defns undef
c
casting
languagelawyer
reinterpretcast
typepunning
C 中的类型双关和联合
我目前正在开发一个项目来构建一个小型编译器 只是为了它 我决定采用构建一个极其简单的虚拟机作为目标的方法 这样我就不必担心学习 elf intel 汇编等的细节 我的问题是关于 C 中使用联合的类型双关 我决定在虚拟机内存中仅支持 32 位
c
typepunning
在 dart 中将整数位模式解析为 IEEE 754 浮点数
我通过接口 蓝牙 列表 获取 4 个字节的数据 数据代表 IEEE 754 浮点数 例如0x3fd0a3d7 大约代表1 63作为二进制32float dart lang 有没有办法将其转换 类型双关为 float 然后 double 就像
dart
floatingpoint
IEEE754
typepunning
uint32_t 和 uint8_t[4] 未定义行为的联合? [复制]
这个问题在这里已经有答案了 在评论中这个答案 https stackoverflow com a 8568531 1025391据说使用如下联合将整数分割成字节将是未定义的行为 该位置给出的代码与此相似但不完全相同 如果我更改了代码的未定义
c
unions
strictaliasing
typepunning
您可以通过 T 的结构为 T 的数组添加别名吗,类似于 std::complex
[N] 如何为 T[N * 2] 别名? [复制]
这个问题在这里已经有答案了 从 C 11 开始std complex
c
languagelawyer
strictaliasing
typepunning
严格的指针别名:针对特定问题的任何解决方案?
我遇到了由于违反严格的指针别名规则而引起的问题 我有一个类型T来自模板和一些整数类型Int相同大小 如sizeof 我的代码基本上执行以下操作 T x some other t if reinterpret cast
c
generics
reinterpretcast
strictaliasing
typepunning
严格的别名规则是什么?
当询问有关C 中常见的未定义行为 https stackoverflow com questions 98340 what are the common undefinedunspecified behavior for c that yo
c
undefinedbehavior
strictaliasing
typepunning
这种类型的双关语定义明确吗?
阅读引用这个答案关于严格的别名规则 我在 C 11 中看到以下内容 如果程序尝试通过以下类型之一以外的泛左值访问对象的存储值 则行为未定义 聚合或联合类型 其元素或非静态数据成员中包括上述类型之一 递归地包括子聚合或包含的联合的元素或非静态
c
undefinedbehavior
typepunning
1
2
»