Why use C typedefs rather than #defines?
Posted
by me_and
on Stack Overflow
See other posts from Stack Overflow
or by me_and
Published on 2010-04-07T10:46:32Z
Indexed on
2010/04/07
10:53 UTC
Read the original article
Hit count: 134
What advantage (if any) is there to using typedef
in place of #define
in C code?
As an example, is there any advantage to using
typedef unsigned char UBYTE
over
#define UBYTE unsigned char
when both can be used as
void func()
{
UBYTE byte_value = 0;
/* Do some stuff */
return byte_value;
}
Obviously the pre-processor will try to expand a #define
wherever it sees one, which wouldn't happen with a typedef
, but that doesn't seem to me to be any particular advantage or disadvantage; I can't think of a situation where either use wouldn't result in a build error if there was a problem.
© Stack Overflow or respective owner