C++ int2、int3、float2、float3 等类型呢?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4079451/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 14:29:58  来源:igfitidea点击:

What about the types int2, int3, float2, float3 etc

c++

提问by Moberg

I've seen different code snippets using these types, but I haven't seen if they are defined in some <standard header file> or just defined in a "local header file" or even at file level.

我见过使用这些类型的不同代码片段,但我还没有看到它们是在某些 <标准头文件> 中定义的,还是只是在“本地头文件”中甚至在文件级别中定义的。

So what Im wondering is: Is there any standard header file that defines these types? Or is there some standard definitions that everyone uses that I should copy?

所以我想知道的是:有没有定义这些类型的标准头文件?或者是否有一些每个人都使用的标准定义我应该复制?

I guess that a possible and common use to these types are representing coordinates, am I wrong?

我猜这些类型的可能和常见用途是表示坐标,我错了吗?

Is there anything else I should think about if I want to use these to represent positions in a grid? Any reasons why or why not to use them?

如果我想用这些来表示网格中的位置,还有什么我应该考虑的吗?为什么或为什么不使用它们的任何原因?

EDIT:

编辑:

Clarification: int2 means a pair of ints, float3 means a triplet of floats.

说明:int2 表示一对整数,float3 表示一组浮点数。

If these types were predefined somewhere it would be nice to use them instead of having to write it from scratch including the standard algebraic functions (operator+, operator-, etc.).

如果这些类型是在某处预定义的,那么使用它们而不是从头开始编写包括标准代数函数(operator+、operator- 等)会很好。

回答by jalf

These types aren't a part of standard C++. They might either be defined in some third-party library, or you're looking at some other dialect or language.

这些类型不是标准 C++ 的一部分。它们可能在某些第三方库中定义,或者您正在查看其他方言或语言。

GPU code (Shader languages such as GLSL, Cg or HLSL, or GPGPU stuff like CUDA or OpenCL) typically defines types like these though, as names for the corresponding SIMD datatypes.

GPU 代码(着色器语言,如 GLSL、Cg 或 HLSL,或 GPGPU 的东西,如 CUDA 或 OpenCL)通常将这些类型定义为相应的 SIMD 数据类型的名称。

回答by Martin Beckett

They are used in CUDA (and openCL?) where you have specific sized floats and memory usage and alignment is a big deal.

它们用于 CUDA(和 openCL?),在那里你有特定大小的浮点数,内存使用和对齐很重要。

回答by vitaut

AFAIK there is no standard header file that defines these types. According to your description int2means a pair of two ints which can be represented in C++ as std::pair<int, int>.

AFAIK 没有定义这些类型的标准头文件。根据您的描述int2是指一对两个ints 可以在 C++ 中表示为std::pair<int, int>.

回答by Jay

I stay with the POSIX types defined in <stdint.h>. It seems like everyone defines their own names for things and I've had a project where the names collide. It's become a new paradigm for me to NOT define my own "pet" names for types.

我仍然使用 <stdint.h> 中定义的 POSIX 类型。似乎每个人都为事物定义了自己的名称,而我有一个名称冲突的项目。不为类型定义自己的“宠物”名称已成为我的新范式。

回答by aschepler

These types are not standard and I've never seen them. Are you sure they weren't used as (terrible choices of) identifiers instead of types?

这些类型不是标准的,我从未见过它们。您确定它们没有用作(可怕的选择)标识符而不是类型吗?

Some non-standard types that are quite likely available anyway are int32_t, uint64_t, etc. (These are specified by C99, so most modern C++ compilers also let you use them in C++.)

一些不规范的类型是很可能获得反正是int32_tuint64_t等(这是由C99指定的,所以大多数现代C ++编译器也让你用C使用它们++)。