Mail Archives: djgpp/1996/03/24/07:34:55
Eli Zaretskii <eliz AT is DOT elta DOT co DOT il> wrote:
>> enough, "typedef" means something completely different in gcc than in
>> standard C compilers. Is there a way to let typedef do the standard
>> thing?
>You've read it wrong, `typedef' in gcc does the same that it does in any
>other compiler. `typedef' is an ANSI-standard feature and gcc is
>ANSI-compliant compiler.
Yes, I was wrong. I typed in "typedef asdf long;" and got a compiler
error. I then did a "info gcc" and got to the following paragraph:
Naming an Expression's Type
===========================
You can give a name to the type of an expression using a `typedef'
declaration with an initializer. Here is how to define NAME as a type
name for the type of EXP:
typedef NAME = EXP;
This is useful in conjunction with the tatements-within-expressions
feature. Here is how the two together can be used to define a safe
"maximum" macro that operates on any arithmetic type:
#define max(a,b) \
({typedef _ta = (a), _tb = (b); \
_ta _a = (a); _tb _b = (b); \
_a > _b ? _a : _b; })
The reason for using names that start with underscores for the
local variables is to avoid conflicts with variable names that occur
within
--Info: (gcc.inf)Naming Types, 28 lines --Top-- Subfile: gcc.i8--
I-search: typedef
--
Weiqi Gao
weiqigao AT crl DOT com
- Raw text -