简体   繁体   English

typedef在内部如何工作?

[英]How does typedef work internally?

As the question goes how does typedef work internally? 随着问题的发展, typedef在内部如何工作?

PS : I did search in various websites including Wikipedia and various. PS:我确实在包括Wikipedia在内的各种网站中进行搜索。 But none of them answer this. 但是他们都没有回答。 Hence the question. 因此是一个问题。

To clarify further : I did get to what it does but how it does is the question. 为了进一步澄清:我确实了解了它的作用,但是它的作用是问题。

typedef is the keyword in C , which provides the programmer a tool to make an alias of own typedefC的关键字,它为程序员提供了一个工具自己的别名的工具

data type from the other types or existing built-in types. data type与其他类型的或现有的内置类型。

This is how the language is and this is how it's implemented. 这就是语言的方式以及实现方式。

typedef <given_type> <new_type>

FYI : if you do 仅供参考:如果您这样做

int a it parsed by compiler and then it came to know that a is a variable of type int . int a由编译器解析,然后得知aint类型的变量。 And accordingly memory is assigned and all. 并因此分配了所有内存。

Similarly whenever typedef keyword found then it assumes that the type just following it is the old_type and other new identifier is new_type . 同样,只要找到typedef关键字,它就会假定紧随其后的类型是old_type ,其他新标识符是new_type

EDIT : 编辑:

ISO c99 : Storage-class specifiers ISO c99:存储级说明符

The typedef specifier is called a ''storage-class specifier'' for syntactic convenience only.If, in a parameter declaration, an identifier can be treated either as a typedef name or as a parameter name, it shall be taken as a typedef name.A typedef declaration does not introduce a new type, only a synonym for the type so specified

How any compiler handles a typedef isn't specified; 没有指定任何编译器如何处理typedef most likely the type information is saved as part of the symbol table entry for that name, and everywhere the type name is encountered in the source code, the equivalent type information is substituted during translation. 类型信息很可能被保存为该名称的符号表条目的一部分,并且在源代码中遇到类型名称的任何地方,都将在转换过程中替换等效的类型信息。

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

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