简体   繁体   English

C ++ typedef(来自MATLAB)

[英]C++ typedefs (from MATLAB)

I'm looking through some c++ code that MATLAB generated and I came across this: 我正在查看MATLAB生成的一些c ++代码,发现了这一点:

typedef char char_T
typedef char_T byte_T

What exactly is this code doing and what is its purpose? 该代码的作用是什么?其目的是什么?

What I think you're asking is for the reason why MATLAB's code generator is spitting out these seemingly superfluous typedefs. 我想您要问的原因是MATLAB的代码生成器吐出这些看似多余的typedef的原因。 The probable reason being that MATLAB wants a type that represents bytes for its code, but it's unsure of what that type is on your specific system and architecture. 可能的原因是MATLAB想要一种代表其代码字节的类型,但是不确定该类型在您的特定系统和体系结构上是什么。 It then probably has a system-specific stub that maps its own types to something reasonable, and then a generic portion that uses those previously-established types. 然后,它可能具有特定于系统的存根,该存根将其自身的类型映射到某种合理的对象,然后将其使用那些先前建立的类型的通用部分映射。

Well, the main theorem of programming states that any problem can be solved via adding one more layer of indirectness. 好吧,编程的主要定理指出,任何问题都可以通过增加一层间接性来解决。 The hypothetical purpose of the typedef is to use char_T everywhere, and if, say one day one decides to change the "byte type" to, say, unsigned char, one changes it to typedef的假设目的是在各处使用char_T,如果某天有人决定将“字节类型”更改为例如unsigned char,则将其更改为

typedef signed char charT

and there is no need to look for every place you used char and change manually. 并且无需查找您使用char的每个位置并手动进行更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM