Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Pointers and Sequence Point |
| Date | 2011-05-03 05:33 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <ipoi5k$lht$1@dont-email.me> (permalink) |
| References | <4dbe97cd$0$311$14726298@news.sunsite.dk> <ipmdaj$8dk$1@dont-email.me> <77ea7b06-dc58-48b0-bd17-4797d4150058@22g2000prx.googlegroups.com> <ipnsam$bv2$1@dont-email.me> <lnei4guwog.fsf@nuthaus.mib.org> |
On 05/03/2011 02:26 AM, Keith Thompson wrote: > James Kuyper <jameskuyper@verizon.net> writes: >> On 05/02/2011 12:36 PM, Chad wrote: >>> On May 2, 6:58�am, Martin Ambuhl <mamb...@earthlink.net> wrote: >>>> On 5/2/2011 7:38 AM, arnuld wrote: >>>> >>>>> I have this program which is causing confusion to me. I am told that last >>>>> printf() of main() will always print "Second", not "First". I think line: >>>> >>>>> � x = myAlloc(x); >>>> >>>> While it is possible to write evil code in which myAlloc could modify x, >>>> in C myAlloc receives a copy of the value of x and has no clue where x >>>> is or how to modify it. �There are not two or more instances of >>>> modifying x between sequence points. >>>> >>> >>> What is the scope of 'x' in myAlloc(x)? Is confined to myAlloc()? >> >> The scope of 'x' starts at the declaration of 'x' on the first line of >> main(), and is restricted to the body of main(). It goes out of scope >> throughout the execution of myAlloc(). It comes back into scope after >> that function returns. It's scope ends when main() returns. > > Your wording seems to imply that 'x' goes into and out of scope > during execution. In fact, an entity's scope is a region of > program text. C99 6.2.1p2. As the program executes, it executes code corresponding to those different regions of text, and that's what I was trying to talk about. However, that correspondence gets complicated to talk about accurately, especially after optimization. I should really have emphasized that scope is a compile-time concept, not a run-time one. The key point is that that all of the operations that might, in some other context, be problematic, are performed on a variable named 'c', whose scope is restricted to myAlloc(), that happens to be initialized with the value of 'x' at the time myAlloc() is called. As a result, they're not at all problematic. -- James Kuyper
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Pointers and Sequence Point arnuld <sunrise@invalid.address> - 2011-05-02 11:38 +0000
Re: Pointers and Sequence Point James Kuyper <jameskuyper@verizon.net> - 2011-05-02 08:23 -0400
Re: Pointers and Sequence Point Martin Ambuhl <mambuhl@earthlink.net> - 2011-05-02 09:58 -0400
Re: Pointers and Sequence Point Chad <cdalten@gmail.com> - 2011-05-02 09:36 -0700
Re: Pointers and Sequence Point Angel <angel+news@spamcop.net> - 2011-05-02 17:21 +0000
Re: Pointers and Sequence Point James Kuyper <jameskuyper@verizon.net> - 2011-05-02 23:20 -0400
Re: Pointers and Sequence Point Keith Thompson <kst-u@mib.org> - 2011-05-02 23:26 -0700
Re: Pointers and Sequence Point James Kuyper <jameskuyper@verizon.net> - 2011-05-03 05:33 -0400
Re: Pointers and Sequence Point Kenneth Brody <kenbrody@spamcop.net> - 2011-05-02 13:35 -0400
Re: Pointers and Sequence Point Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-05-03 17:45 +0300
Re: Pointers and Sequence Point John Bode <jfbode1029@gmail.com> - 2011-05-02 10:17 -0700
Re: Pointers and Sequence Point Tim Rentsch <txr@alumni.caltech.edu> - 2011-05-02 10:31 -0700
Re: Pointers and Sequence Point "Morris Keesan" <mkeesan@post.harvard.edu> - 2011-05-02 20:55 -0400
Re: Pointers and Sequence Point David Resnick <lndresnick@gmail.com> - 2011-05-03 08:01 -0700
csiph-web