Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #31844
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!aioe.org!.POSTED!not-for-mail |
|---|---|
| From | "Rod Pemberton" <dont_use_email@xnothavet.cqm> |
| Newsgroups | comp.lang.forth |
| Subject | Re: C array descriptor |
| Date | Wed, 25 Jun 2014 18:13:47 -0400 |
| Organization | Aioe.org NNTP Server |
| Lines | 53 |
| Message-ID | <op.xh06o9r46zenlw@localhost> (permalink) |
| References | <eff9d8fc-6d13-4e4b-9a01-33be4550e27d@googlegroups.com> <bZKdnd1wUcOMGjfOnZ2dnUVZ_tWdnZ2d@supernews.com> |
| NNTP-Posting-Host | CNsg4fVcCsvs3UaOgZtQCw.user.speranza.aioe.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=iso-8859-1; format=flowed; delsp=yes |
| Content-Transfer-Encoding | 7bit |
| X-Complaints-To | abuse@aioe.org |
| User-Agent | Opera Mail/12.16 (Linux) |
| X-Notice | Filtered by postfilter v. 0.8.2 |
| Xref | csiph.com comp.lang.forth:31844 |
Show key headers only | View raw
On Wed, 25 Jun 2014 04:23:45 -0400, Andrew Haley
<andrew29@littlepinkcloud.invalid> wrote:
> Roger Levy <roger.levy@gmail.com> wrote:
>> For the first time, I need to pass an array to an external function.
>> Does anyone know the data structure for C array descriptors?
>
Roger,
You want a pointer. For most compilers, the pointer will point to
the address of the zero'th element of the array, i.e., the starting
address.
> C doesn't have array descriptors. An array, when passed to a
> function, decays into a pointer to the first element.
>
Andrew,
C doesn't have arrays either. C has pointers. C has a subscript
operator [] which uses a pointer and scaled index. What C has is
the ability to declare the space for an array. That's it. That's
the *only* thing in C that C has which involves an array.
int main(void)
{
int abc[10]; /* array declaration */
abc[2]=3; /* no array here */
#if 0
[] is the subscript operator
the subscript operator takes a non-void pointer and an index
the subscript operator scales the index by the data size
the subscript operator sums the pointer and scaled index
abc is that pointer
2 is the index
3 is a value to store at the pointer+index*sizeof(int)
#endif
return(0);
}
As you can clearly see, the "array" is *NOT* passed to a function and
therefore shouldn't have "decayed into" a pointer to the first element.
Yet, the "array" in the code body *IS* a pointer to the first element.
Rod Pemberton
P.S. Andrew, I really can't believe anyone let you maintain GCC.
Anton who is usually wrong about things knows more about how C
works and should work than you.
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
C array descriptor Roger Levy <roger.levy@gmail.com> - 2014-06-24 19:45 -0700
Re: C array descriptor Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-06-25 03:23 -0500
Re: C array descriptor Segfaults R Us <seg4u@segue.org> - 2014-06-25 08:45 +0000
Re: C array descriptor Roger Levy <roger.levy@gmail.com> - 2014-06-25 07:03 -0700
Re: C array descriptor "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-06-25 18:13 -0400
Re: C array descriptor Roger Levy <roger.levy@gmail.com> - 2014-06-25 17:03 -0700
Re: C array descriptor Lars Brinkhoff <lars.spam@nocrew.org> - 2014-06-26 08:12 +0200
Re: C array descriptor "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-06-26 18:07 -0400
Re: C array descriptor Lars Brinkhoff <lars.spam@nocrew.org> - 2014-06-27 07:50 +0200
Re: C array descriptor Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-06-26 04:10 -0500
Re: C array descriptor "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-06-26 18:07 -0400
Re: C array descriptor bruce.mcfarling@gmail.com - 2014-06-26 22:14 -0700
Re: C array descriptor Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-06-27 03:39 -0500
Re: C array descriptor Mark Wills <markwills1970@gmail.com> - 2014-06-27 03:32 -0700
Re: C array descriptor Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-06-27 06:00 -0500
Re: C array descriptor Roger Levy <roger.levy@gmail.com> - 2014-06-27 07:34 -0700
Re: C array descriptor bruce.mcfarling@gmail.com - 2014-06-27 09:42 -0700
Re: C array descriptor Roger Levy <roger.levy@gmail.com> - 2014-06-27 09:51 -0700
Re: C array descriptor bruce.mcfarling@gmail.com - 2014-06-27 15:32 -0700
Re: C array descriptor Bernd Paysan <bernd.paysan@gmx.de> - 2014-06-27 03:40 +0200
csiph-web