Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Issue on assigning address to pointers Date: Wed, 18 Nov 2015 06:13:23 -0800 Organization: None to speak of Lines: 42 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="16979"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/lBeik7AGuzU6B8YCzkiB3" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:DWYvf341VsvivncAvVtRh6BAHNE= sha1:e4Q2NlT2jZJv1of8jdA0niCcuuU= Xref: csiph.com comp.lang.c:76399 Lőrinczy Zsigmond writes: >> The code above sets the array arrayname to zero. This method of getting >> at array data is not recommended by this author except in very simple >> computer environments. If a program is running on a normal microcomputer, >> then there should be few problems with this alternative method of handling >> arrays. On the hand, if the microcomputer is multi-tasking, or the program >> is running on a larger system which has a limited manager, then memory >> ceases to be something which can be thought of as a sequence of boxes >> standing next to one another. A multi-tasking system shares memory with >> Questions 175 >> other programs and it takes what it can find, where it can find it. The upshot >> of this is that it is not possible to guarantee that arrays will be stored in one >> simple string of memory locations: it might be scattered around in different >> places. So >> ptr = arrayname + 5; >> might not be a pointer to the fifth character in a character array. This could >> be found instead using the '&' operator. A pointer to the fifth element can >> be reliably found with: >> ptr =&(arrayname[5]); >> Be warned! > > If it is original, then it is about some theoretical implementation of C > that never has actually been created... It's not about any conforming implementation of C. It's simply about the author's misunderstanding. > On another note, you *can* create your own array-types where elements > aren't continuous: > > OwnElem *p1= OwnAccess (OwnArray, 1); > OwnElem *p2= OwnAccess (OwnArray, 2); > > p2 might or might not be p1+1 That's not an array type, though it might have some array-like properties. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"