Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | BartC <bc@freeuk.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: C language declaration "bugs" |
| Date | 2016-10-11 16:31 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <ntj0jo$d21$1@dont-email.me> (permalink) |
| References | <90bf0ba6-5094-4551-8cc0-c60214b14362@googlegroups.com> <87d1j7avp8.fsf@bsb.me.uk> <b4976e0d-cedb-4721-a261-d3597eb43b97@googlegroups.com> <87zimb9e5b.fsf@bsb.me.uk> <ad00e1c6-3c8b-48f5-b9da-d6f53d159cde@googlegroups.com> |
On 11/10/2016 15:41, Thiago Adams wrote:
> On Tuesday, October 11, 2016 at 11:03:21 AM UTC-3, Ben Bacarisse wrote:
>> Thiago Adams writes:
>
>>> I can't find any options to express dynamic arrays in structs.
>>
>> No, you can't, other than the "struct hack" of putting a flexible array
>> member (i.e. an incomplete array declaration) as the last member.
>
>
> Just to add one more case :
>
> int [] F();
>
> Function returning many int's.
>
> So..when we see
>
> Type* F(); //F singular (GetItem) pointer to one
> Type* F(); //F plural (GetItems) pointer to many
It might be a good idea to have a way of designating a pointer to
multple elements. But [] is overloaded already.
C however already has a way of doing that:
int (*F())[]; // or:
int (*F())[] {...}
(The last example might look odd, as you don't often see [] just before
the { of a function body.)
This says the function returns a pointer to an array; pretty much what
we're after.
Except that hardly anyone who programs in C likes using pointers to
actual arrays (not in this group anyway). Everyone prefers pointers to
elements.
Partly, that's because of the awful syntax involved in declaring such
types and using them.
So, if you need to invent new syntax, it needs to be simpler than array
syntax. You also have to decide, when p is regular pointer, and q points
to a multiple, whether p[i] or (p+i) should still be allowed.
For compatibility reasons, it would have to be. But then that means
three kinds of pointer would be needed:
* Standard C pointer that can target single or multiple objects
* Pointers to single objects
* Pointers to multiple objects
Otherwise there would be little point.
--
Bartc
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
C language declaration "bugs" Thiago Adams <thiago.adams@gmail.com> - 2016-10-11 05:17 -0700
Re: C language declaration "bugs" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-10-11 13:58 +0100
Re: C language declaration "bugs" Thiago Adams <thiago.adams@gmail.com> - 2016-10-11 06:47 -0700
Re: C language declaration "bugs" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-10-11 15:03 +0100
Re: C language declaration "bugs" Thiago Adams <thiago.adams@gmail.com> - 2016-10-11 07:41 -0700
Re: C language declaration "bugs" BartC <bc@freeuk.com> - 2016-10-11 16:31 +0100
Re: C language declaration "bugs" Keith Thompson <kst-u@mib.org> - 2016-10-11 10:01 -0700
Re: C language declaration "bugs" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-10-11 19:10 +0100
Re: C language declaration "bugs" BartC <bc@freeuk.com> - 2016-10-11 14:14 +0100
csiph-web