简体   繁体   中英

how typedef works internally (at compiler level)?

i come across this question in an interview recently. they asked me when we create new user defined Type using Typedef (Like typedef unsigned char CHAR) what happens internally??

Internally there will happen nothing because it is only the information for the compiler that you introduced some alias for another type.

According to the C Standard (6.7.8 Type definitions)

  1. ...A typedef declaration does not introduce a new type, only a synonym for the type so specified.

Take into account that opposite to C++ in C there is no such a notion as the user defined type. The C Standard does not use such a term.

To define a user type you have to specify its behaviour. The C language does not allow to specify behaviours of types.:)

As for the "memory level" then the only consequence is that you can forget what actual type this typedef alias denotes.:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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