home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!stanford.edu!nntp.Stanford.EDU!dkeisen
- From: dkeisen@leland.Stanford.EDU (Dave Eisen)
- Subject: Re: Question to test general C knowledge
- Message-ID: <1992Dec18.203347.21977@leland.Stanford.EDU>
- Sender: news@leland.Stanford.EDU (USENET News System)
- Organization: Sequoia Peripherals, Inc.
- Date: Fri, 18 Dec 92 20:33:47 GMT
- Lines: 34
-
- >
- >Now, as it happens, I have been unable to think of a way to write a
- >compiler such that `i = ++i' would act as if it were `i += 2'---a truly
- >dumb compiler will simply emit all preincrements before handling the
- >rest of the expression, and a truly smart one will notice that i
- >appears twice (and, one hopes, emit a warning) and only generate one
- >increment.
-
-
- Sure, a compiler that is paying attention will recognize "i = ++i"
- and emit a warning or do the right thing or whatever. But the
- semantically equivalent code:
-
- int i;
-
- foo ()
- {
- bar (&i);
- }
-
- bar (int *p)
- {
- *p = ++i;
- }
-
- could easily do the wrong thing and there is no sane way to
- make sure that it doesn't.
-
-
- --
- Dave Eisen Sequoia Peripherals: (415) 967-5644
- dkeisen@leland.Stanford.EDU Home: (415) 321-5154
- There's something in my library to offend everybody.
- --- Washington Coalition Against Censorship
-