Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #164052
| From | Meredith Montgomery <mmontgomery@levado.to> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: isn't an array a contiguous region of memory? |
| Date | 2021-12-21 21:43 -0300 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <86h7b131vo.fsf@levado.to> (permalink) |
| References | <86tuf13fvc.fsf@levado.to> <sptcrs$f5q$1@dont-email.me> |
Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
> On Tue, 21 Dec 2021 16:41:27 -0300, Meredith Montgomery wrote:
[...]
>> I'm very surprised by the memory location 6446082752 being an integer
>> greater than 6446078248. As you can see in the source code, the
>> first number is &argv[0] and the second is &argv[1]. In my mind, the
>> latter should be *always* greater than the former.
[...]
> First off,
> char *argv[]
> defines argv as an array of {pointer to char}, so each element of argv
> (each argv[something]) contains a pointer.
>
> Now, the pointers may point to various places, and not maintain an
> ascending order. So argv[0] can hold a pointer that points to
> address 1000
> and
> argv[1] can hold a pointer that points to address 500
> and this difference does not affect the order or spacing of the array.
>
> In your example,
> argv[0] is located at address 4294954096, and holds a pointer that
> points somewhere
> while
> argv[1] is located at address 4294954104, and holds a pointer that
> points somewhere else.
>
> Note that your argv[1] is 8 bytes further along than argv[0]. That 8
> bytes is the size of the pointer (and, possibly some padding) that
> argv[0] holds within itself.
I think you're showing me that the addresses of each position in the
array are really in memory-ascending-order, but the values in each array
bucket (say), could be any numbers at all. That makes perfect sense.
Wait. I did not present the problem properly. But your answer is the
answer that I was looking for anyhow. I was confused --- I thought that
&argv[0] and &argv[1] would be the same values as argv[0] and argv[1].
You know that's not true. When I presented the difficulty here I did
not realized that I had changed the program to print &argv[0] and
&argv[1] --- and that explains why I couldn't reproduce ``the problem''
because, indeed, to reproduce it I must write argv[0] and argv[1], two
addresses that can totally be any numbers at all. Order is back in the
house. I apologize for the mess.
> Try this example to see if it makes things clearer:
It did! Thanks so much.
[...]
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
isn't an array a contiguous region of memory? Meredith Montgomery <mmontgomery@levado.to> - 2021-12-21 16:41 -0300
Re: isn't an array a contiguous region of memory? scott@slp53.sl.home (Scott Lurndal) - 2021-12-21 20:10 +0000
Re: isn't an array a contiguous region of memory? scott@slp53.sl.home (Scott Lurndal) - 2021-12-21 20:13 +0000
Re: isn't an array a contiguous region of memory? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2021-12-21 20:19 +0000
Re: isn't an array a contiguous region of memory? Meredith Montgomery <mmontgomery@levado.to> - 2021-12-21 21:43 -0300
Re: isn't an array a contiguous region of memory? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-12-21 12:22 -0800
Re: isn't an array a contiguous region of memory? Meredith Montgomery <mmontgomery@levado.to> - 2021-12-21 21:48 -0300
Re: isn't an array a contiguous region of memory? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2021-12-22 16:38 -0800
Irreproducible results (Was: isn't an array a contiguous region of memory?) gazelle@shell.xmission.com (Kenny McCormack) - 2021-12-23 12:46 +0000
Re: Irreproducible results Meredith Montgomery <mmontgomery@levado.to> - 2021-12-25 21:57 -0300
csiph-web