www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/03/24/07:34:55

Xref: news2.mv.net comp.os.msdos.djgpp:2099
From: weiqigao AT crl DOT com (Weiqi Gao)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: typedefs
Date: Fri, 22 Mar 1996 04:31:14 GMT
Organization: Spectrum Healthcare Services
Lines: 41
Message-ID: <4ita7b$nk4@nntp.crl.com>
References: <4i1ctq$neh AT nntp DOT crl DOT com> <Pine DOT SUN DOT 3 DOT 91 DOT 960321181041 DOT 25389G-100000 AT is>
Reply-To: weiqigao AT crl DOT com
NNTP-Posting-Host: crl13.crl.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019