Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #31803 > unrolled thread
| Started by | Roger Levy <roger.levy@gmail.com> |
|---|---|
| First post | 2014-06-24 19:45 -0700 |
| Last post | 2014-06-27 03:40 +0200 |
| Articles | 20 — 8 participants |
Back to article view | Back to comp.lang.forth
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
| From | Roger Levy <roger.levy@gmail.com> |
|---|---|
| Date | 2014-06-24 19:45 -0700 |
| Subject | C array descriptor |
| Message-ID | <eff9d8fc-6d13-4e4b-9a01-33be4550e27d@googlegroups.com> |
For the first time, I need to pass an array to an external function. Does anyone know the data structure for C array descriptors?
[toc] | [next] | [standalone]
| From | Andrew Haley <andrew29@littlepinkcloud.invalid> |
|---|---|
| Date | 2014-06-25 03:23 -0500 |
| Message-ID | <bZKdnd1wUcOMGjfOnZ2dnUVZ_tWdnZ2d@supernews.com> |
| In reply to | #31803 |
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? C doesn't have array descriptors. An array, when passed to a function, decays into a pointer to the first element. Andrew.
[toc] | [prev] | [next] | [standalone]
| From | Segfaults R Us <seg4u@segue.org> |
|---|---|
| Date | 2014-06-25 08:45 +0000 |
| Message-ID | <loe27d$ms3$4@solani.org> |
| In reply to | #31807 |
On 2014-06-25, 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? > > C doesn't have array descriptors. An array, when passed to a > function, decays into a pointer to the first element. Can you say "segfault" boys and girls? ;-) > > Andrew.
[toc] | [prev] | [next] | [standalone]
| From | Roger Levy <roger.levy@gmail.com> |
|---|---|
| Date | 2014-06-25 07:03 -0700 |
| Message-ID | <cd851998-6174-4c2a-bcd7-1f1b45e3d29b@googlegroups.com> |
| In reply to | #31807 |
So you are right. There is totally a count in the function prototype, and I overlooked it! ALLEGRO_FONT *al_grab_font_from_bitmap(ALLEGRO_BITMAP *bmp, int ranges_n, int ranges[]) On Wednesday, June 25, 2014 4:23:45 AM UTC-4, Andrew Haley 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? > > > > C doesn't have array descriptors. An array, when passed to a > > function, decays into a pointer to the first element. > > > > Andrew.
[toc] | [prev] | [next] | [standalone]
| From | "Rod Pemberton" <dont_use_email@xnothavet.cqm> |
|---|---|
| Date | 2014-06-25 18:13 -0400 |
| Message-ID | <op.xh06o9r46zenlw@localhost> |
| In reply to | #31807 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Roger Levy <roger.levy@gmail.com> |
|---|---|
| Date | 2014-06-25 17:03 -0700 |
| Message-ID | <c5ba226b-8fa2-44ed-bb21-25db4aa6039e@googlegroups.com> |
| In reply to | #31844 |
> 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. You're confusing interface with implementation. C does have arrays. Very basic arrays. Everyone but the nit-pickiest hair-splitters would agree. http://www.zentut.com/c-tutorial/c-array/ BECAUSE of the implementation, the brackets can be abused to behave unlike arrays. That would be an act of obfuscation and also unsafe and therefore bad, but we're talking about C here. > 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. I bet I could maintain GCC. How hard could it be? ;)
[toc] | [prev] | [next] | [standalone]
| From | Lars Brinkhoff <lars.spam@nocrew.org> |
|---|---|
| Date | 2014-06-26 08:12 +0200 |
| Message-ID | <857g44dwrn.fsf@junk.nocrew.org> |
| In reply to | #31844 |
Rod Pemberton writes: > 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. There's also sizeof.
[toc] | [prev] | [next] | [standalone]
| From | "Rod Pemberton" <dont_use_email@xnothavet.cqm> |
|---|---|
| Date | 2014-06-26 18:07 -0400 |
| Message-ID | <op.xh203dwk6zenlw@localhost> |
| In reply to | #31862 |
On Thu, 26 Jun 2014 02:12:44 -0400, Lars Brinkhoff <lars.spam@nocrew.org> wrote: > Rod Pemberton writes: >> 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. > > There's also sizeof. Yeah, but that's still not a use of an array in C. It simply returns the size of the declaration. Rod Pemberton
[toc] | [prev] | [next] | [standalone]
| From | Lars Brinkhoff <lars.spam@nocrew.org> |
|---|---|
| Date | 2014-06-27 07:50 +0200 |
| Message-ID | <85d2dudhoi.fsf@junk.nocrew.org> |
| In reply to | #31896 |
"Rod Pemberton" <dont_use_email@xnothavet.cqm> writes: >> There's also sizeof. > Yeah, but that's still not a use of an array in C. > It simply returns the size of the declaration. It knows about the difference between a pointer and an array.
[toc] | [prev] | [next] | [standalone]
| From | Andrew Haley <andrew29@littlepinkcloud.invalid> |
|---|---|
| Date | 2014-06-26 04:10 -0500 |
| Message-ID | <4cudnW5zj6HmfjbOnZ2dnUVZ_oSdnZ2d@supernews.com> |
| In reply to | #31844 |
Rod Pemberton <dont_use_email@xnothavet.cqm> wrote: > 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. Yes, it does. Read the standard, in particular 6.7.5.2, Array declarators. > 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. No, it's not, it's an array. As the standard puts it, "Except when it is the operand of the sizeof operator or the unary & operator, or is a string literal used to initialize an array, an expression that has type ''array of type'' is converted to an expression with type ''pointer to type'' that points to the initial element of the array object..." And this is exactly what happens at a function call. Like I said. > 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. Oh no! My career is over! Andrew.
[toc] | [prev] | [next] | [standalone]
| From | "Rod Pemberton" <dont_use_email@xnothavet.cqm> |
|---|---|
| Date | 2014-06-26 18:07 -0400 |
| Message-ID | <op.xh202roy6zenlw@localhost> |
| In reply to | #31868 |
On Thu, 26 Jun 2014 05:10:19 -0400, Andrew Haley <andrew29@littlepinkcloud.invalid> wrote: > Rod Pemberton <dont_use_email@xnothavet.cqm> wrote: >> C doesn't have arrays either. > > Yes, it does. Read the standard, in particular 6.7.5.2, Array > declarators. > That's not array. It's a declarator. I mentioned that too: RP> "What C has is the ability to declare the space for an array." >> 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. > > No, it's not, it's an array. No, it's not, it's a pointer. Like I said. Your own quote agrees with me. You need to re-read this again: > As the standard puts it, > > "Except when it is the operand of the sizeof operator or the unary & > operator, or is a string literal used to initialize an array, an > expression that has type ''array of type'' is converted to an > expression with type ''pointer to type'' that points to the initial > element of the array object..." > ... > And this is exactly what happens at a function call. Like I said. It happens at compile time, long before a function call. C treats everything as pointer based. Rod Pemberton
[toc] | [prev] | [next] | [standalone]
| From | bruce.mcfarling@gmail.com |
|---|---|
| Date | 2014-06-26 22:14 -0700 |
| Message-ID | <715dd7d7-4f89-4242-9e99-7c774a05ddcb@googlegroups.com> |
| In reply to | #31895 |
On Thursday, June 26, 2014 6:07:29 PM UTC-4, Rod Pemberton wrote: > C treats everything as pointer based. Which people who speak normal English would express as C-arrays being pointer based. The argument that "it's not a REAL array according to my criteria, its just pointers with operators that allow them to function as if they were arrays" is the kind of pointless semantic quibbling often described as a distinction without a difference. The relevant point to the original question is that the side information regarding the size of the array doesn't go along for the ride with the pointer, so it either has to be implicit in the operation, which expects a pointer to an array of objects of a given size, or has to be passed in the function call, and similarly the number of items either has to be implied by the operation, detectable from the array (as with the nul-terminated character arrays often used as strings) or passed as information in the call.
[toc] | [prev] | [next] | [standalone]
| From | Andrew Haley <andrew29@littlepinkcloud.invalid> |
|---|---|
| Date | 2014-06-27 03:39 -0500 |
| Message-ID | <YOqdnUxRfJ9IsDDOnZ2dnUVZ_sidnZ2d@supernews.com> |
| In reply to | #31895 |
Rod Pemberton <dont_use_email@xnothavet.cqm> wrote: > On Thu, 26 Jun 2014 05:10:19 -0400, Andrew Haley > <andrew29@littlepinkcloud.invalid> wrote: >> Rod Pemberton <dont_use_email@xnothavet.cqm> wrote: > >>> C doesn't have arrays either. >> >> Yes, it does. Read the standard, in particular 6.7.5.2, Array >> declarators. > > That's not array. It's a declarator. I mentioned that too: > > RP> "What C has is the ability to declare the space for an array." You're now pointlessly nitpicking. An array declarator declares an array. > Your own quote agrees with me. You need to re-read this again: > >> As the standard puts it, >> >> "Except when it is the operand of the sizeof operator or the unary & >> operator, or is a string literal used to initialize an array, an >> expression that has type ''array of type'' is converted to an >> expression with type ''pointer to type'' that points to the initial >> element of the array object..." >> > ... > >> And this is exactly what happens at a function call. Like I said. > > It happens at compile time, long before a function call. Of course it happens at compile time. I said that "an array, when passed to a function, decays into a pointer to the first element." You disagreed. The standard actually says that an array "is converted to an expression with type ''pointer to type'' that points to the initial element of the array object..." This means the same thing. Andrew.
[toc] | [prev] | [next] | [standalone]
| From | Mark Wills <markwills1970@gmail.com> |
|---|---|
| Date | 2014-06-27 03:32 -0700 |
| Message-ID | <c286fbef-1e2c-4cec-9abd-7a7435b30a18@googlegroups.com> |
| In reply to | #31929 |
Andrew, don't waste your time!
[toc] | [prev] | [next] | [standalone]
| From | Andrew Haley <andrew29@littlepinkcloud.invalid> |
|---|---|
| Date | 2014-06-27 06:00 -0500 |
| Message-ID | <w_WdnRjgZdJ10zDOnZ2dnUVZ_rmdnZ2d@supernews.com> |
| In reply to | #31930 |
Mark Wills <markwills1970@gmail.com> wrote: > Andrew, don't waste your time! I am sometimes tempted to quote Rushdie, who wrote "It matters, it always matters, to name rubbish as rubbish ... to do otherwise is to legitimize it." But in this case you're probably right. :-) Andrew.
[toc] | [prev] | [next] | [standalone]
| From | Roger Levy <roger.levy@gmail.com> |
|---|---|
| Date | 2014-06-27 07:34 -0700 |
| Message-ID | <3bba053c-25e5-4548-8deb-567f8f846211@googlegroups.com> |
| In reply to | #31932 |
I am so sorry I made this thread. Down with C, Hooray for C, and so on and so Forth!
[toc] | [prev] | [next] | [standalone]
| From | bruce.mcfarling@gmail.com |
|---|---|
| Date | 2014-06-27 09:42 -0700 |
| Message-ID | <bbb6b06e-02a6-4b21-9a97-2687b322e6ea@googlegroups.com> |
| In reply to | #31944 |
On Friday, June 27, 2014 10:34:13 AM UTC-4, Roger Levy wrote: > I am so sorry I made this thread. > > Down with C, Hooray for C, and so on and so Forth! The question is never whether there is any chaff, since there is always chaff ... the question is always whether there was any wheat that could be separated from the chaff.
[toc] | [prev] | [next] | [standalone]
| From | Roger Levy <roger.levy@gmail.com> |
|---|---|
| Date | 2014-06-27 09:51 -0700 |
| Message-ID | <d0ff3289-800f-46f6-bd76-7438a2a4dfd7@googlegroups.com> |
| In reply to | #31957 |
> The question is never whether there is any chaff, since there is always chaff ... the question is always whether there was any wheat that could be separated from the chaff. What are you referring to?
[toc] | [prev] | [next] | [standalone]
| From | bruce.mcfarling@gmail.com |
|---|---|
| Date | 2014-06-27 15:32 -0700 |
| Message-ID | <1dbea210-c6fd-4a9b-8d75-800cc9fdf6e4@googlegroups.com> |
| In reply to | #31960 |
On Friday, June 27, 2014 12:51:48 PM UTC-4, Roger Levy wrote: > > The question is never whether there is any chaff, since there is always chaff ... the question is always whether there was any wheat that could be separated from the chaff. > > What are you referring to? The phrase "separating the wheat from the chaff" ~ anything of value in a USENET Newsgroup discussion being the wheat, the accompanying pointless semantic quibbling and red herring arguments being the chaff.
[toc] | [prev] | [next] | [standalone]
| From | Bernd Paysan <bernd.paysan@gmx.de> |
|---|---|
| Date | 2014-06-27 03:40 +0200 |
| Message-ID | <loii3b$csl$1@online.de> |
| In reply to | #31868 |
Andrew Haley wrote: >> 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. > > Oh no! My career is over! Haha, if Rod, who is fractionally wrong about every topic he posts on in so many ways tells you that you know less than Anton about C, this must be a "wrong", too ;-). The difference we have about C is not about the semantics of the C standard, it is about the way to fill all those gaps in the standard GCC should do. I.e. we think if you start with something as insane as the C standard, the first thing you need to do is to use every undefined part of the standard to make something sane, and add legitimate extensions so that you can do so. RMS did that for various aspects of C, and I think he did a good job (not a great one, because that would have required to fix the two bigest problems: Arrays with bounds and multiple return values - that's what Ken Thompson and Rob Pike did with Go). Some extensions he made even became part of later C standards. -- Bernd Paysan "If you want it done right, you have to do it yourself" http://bernd-paysan.de/
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.forth
csiph-web