C++ typedefs (from MATLAB)
I'm looking through some c++ code that MATLAB generated and开发者_如何学C I came across this:
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. 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. 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 signed char charT
and there is no need to look for every place you used char and change manually.
精彩评论