Path: utzoo!attcan!uunet!ogicse!mintaka!bloom-beacon!athena.mit.edu!rsfinn From: rsfinn@athena.mit.edu (Russell S. Finn) Newsgroups: comp.sys.mac.programmer Subject: Re: Think C Preprocessor Question Message-ID: <1990Oct24.223243.12287@athena.mit.edu> Date: 24 Oct 90 22:32:43 GMT References: <13065@crdgw1.crd.ge.com> Sender: daemon@athena.mit.edu (Mr Background) Reply-To: rsfinn@athena.mit.edu (Russell S. Finn) Organization: Massachusetts Institute of Technology Lines: 24 In article <13065@crdgw1.crd.ge.com>, darweesh@zephyrus.crd.ge.com (Michael Darweesh) writes: |> Does the C preprocessor ever do any calculations or does it only do search |> and replace? No. That is, it doesn't do calculations (within #define statements, anyway), and it doesn't just search and replace -- let's look at your example: |> #define foo 5 |> #define bar 8 |> #define baz ((foo * bar) >> 1) |> |> integer = baz; The preprocessor will replace "baz", then rescan the input and replace "foo" and "bar" as well, so the compiler ultimately sees integer = ((5 * 8) >> 1); Now, any self-respecting C compiler will perform this computation at compile-time, which is what you probably wanted all along. (I suspect that this is not guaranteed by the standard, but then, I'm not Doug Gwyn...) Russell S. Finn rsfinn@{athena,lcs}.mit.edu