Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Sat, 11 Jun 2011 12:56:27 -0500 Message-ID: <4DF3AC4F.502B@mindspring.com> Date: Sat, 11 Jun 2011 13:56:31 -0400 From: pete Reply-To: pfiland@mindspring.com Organization: PF X-Mailer: Mozilla 3.04Gold (WinNT; I) MIME-Version: 1.0 Newsgroups: comp.lang.c Subject: Re: a doubt about c References: <7523b6ca-ef28-41c3-99d8-c60273641ddf@glegroupsg2000goo.googlegroups.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 23 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.154.216.252 X-Trace: sv3-CkpsVwVfnlaGryPPRr9jqHHKX9bslzIVQ3tGE39cQIhjj9stgdSnxUXbCWZZ9N3KtpNOOI4lMPFw50i!5jsYIEe6oWkkdhu0OGYUI6RFRS5B/zAV9u52JuYYMnKKieNbc2Dn5vLHRJZawcgwttwAHe6NYSO+!WWe1GmL5U7E= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 1927 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:5846 Shao Miller wrote: > > On 6/11/2011 8:11 AM, Ya Shou wrote: > >... > > I read some open source c program code, found a problem that let me doubt. > > All those programs are using macros to define constants, and did not use an enum to achieve, but I think in the enumeration constants is very convenient. > > Enumeration defines constants used in c++, but not seen any in c, why? > > ... > > If you mean "integer constant expressions," I prefer to use 'enum's in C > wherever possible. > > If an integer constant expression needs to be used as part of an '#if' > pre-processing directive, then I will '#define' and use a macro whose > definition will not contain any identifiers (except other macros) or > keywords. > > #define ALL_ONES_CHAR ((1 << CHAR_BIT) - 1) That's undefined if sizeof (int) equals one. -- pete