Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.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: Tue, 28 Aug 2012 22:47:36 -0500 Message-ID: <503D90D7.E67@mindspring.com> Date: Tue, 28 Aug 2012 23:47:35 -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: #define BYTES *8 References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 40 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.154.223.27 X-Trace: sv3-CMdhDIU64lHvEuAZVgGxlZtWD6t4LSDRcGlojNHgSVkYNjks9iF2pDnbHQitE+B1IBH11bmahGNB1dn!4c2JyfopDB54MdmyrUC1jULVbQdwYd36PFlavbb3zxOvb29s884toi2Oqg9Bbps69Mb2LCD/Mxi0!3vcfdOAf 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: 2160 Xref: csiph.com comp.lang.c:25351 JohnF wrote: > > Anything wrong with that, i.e., with #define BYTES *8 > to multiply by 8? It looked a little weird to me, but > the more obvious #define BYTES(x) ((x)*8) isn't what > I wanted to write. This was to express units of measurement, > e.g., int bits = so_many BYTES; rather than > int bits=BYTES(so_many); . I just wanted to read and write > it the first way, and my test program > #define BYTES *8 > #include > int main ( int argc, char *argv[] ) { > int bytes=(argc<2?1:atoi(argv[1])), > bits = bytes BYTES; > printf("%d bytes = %d bits\n",bytes,bits); > return(0); } > works fine (and compiles with no -pedantic warnings). > But that #define BYTES *8 still looks a little funky to me. > I realize 2+2 BYTES must be written (2+2)BYTES, but is there > any other kind of "gotcha"? #include #include #include #define BITS(X) ((X) * CHAR_BIT) int main (int argc, char *argv[]) { unsigned bytes = argc < 2 ? 1 : atoi(argv[1]); unsigned bits = BITS(bytes); printf("%u bytes = %u bits\n", bytes, bits); return 0; } -- pete