Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #164054
| From | Andrey Tarasevich <andreytarasevich@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: isn't an array a contiguous region of memory? |
| Date | 2021-12-22 16:38 -0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <sq0gdk$lnu$1@dont-email.me> (permalink) |
| References | <86tuf13fvc.fsf@levado.to> |
On 12/21/2021 11:41 AM, Meredith Montgomery wrote: > > My idea of an array is a contiguous region of memory. But I was totally > surprised what I saw today and I can't make any sense of this. Here's > what I did. I wrote the program below, which produced the executable > argv.exe. I renamed it to a.exe and ran it as ``./a.exe a bc d''. 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. > Yes, it should be. The first result you quoted makes no sense. The only possible explanation is that you are most certainly making something up in the first quoted output. Yes, it is possible that `unsigned long` is too narrow to represent a pointer value on your platform, but it still wouldn't normally produce the result you quoted. Meanwhile, the second result you quoted makes perfect sense. So, yes, an array _is_ a contiguous region of memory and `&argv[1]` is always greater than `&argv[0]`. And next time you want to convert a pointer value to an integer, please use `uintptr_t` (and `PRIuPTR` to print it). This will eliminate this additional and completely unnecessary source of confusion. -- Best regards, Andrey Tarasevich
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