is primitive data type in c macro?
In c, are primitive data types such as "int" "long" "char" "unsigned"... all macros? I开发者_StackOverflow社区f so, where are they defined? And how are they implemented such as "int" type?
They are not macros, they are just converted by the compiler into the appropriate data storage and operations.
For example when you have in your program:
int i;
i=5
i+=7;
The compiler translates it to something similar to this:
Allocate sizeof(int) bytes in the stack
Put the number 5 in the allocated space
Retrieve the number on the allocated space, add 7 to it, and save it again at the same location
Some standard types (often, things like size_t
or uintptr_t
or ptrdiff_t
) are implemented as typedefs or macros. But the compiler needs some "primitive" or "fundamental" types (such as char
, int
, and so on), which are built into the compiler and not defined in header files.
They are no macros. Every programming language needs primary types that aren't macros but are rather part of the languages syntax tree. The compiler will translate these primitive datatypes directyl into the appropriate binary representation.
I think you also misunderstood how macros are used. There are types that are defined by means of other types via typedef.
typedef unsigned short BOOL;
You could do that with a macro but this won't give you full compiler checking, that's why you should prefer tyepef.
The primitive datatypes like int
, char
, float
, etc. are defined in the C standard, and the compiler knows them intrinsically. Other types like uint32_t
are typedefs defined in header files, and they're defined in terms of the primitive types.
精彩评论