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 14:14 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <ntioih$f8k$1@dont-email.me> (permalink) |
| References | <90bf0ba6-5094-4551-8cc0-c60214b14362@googlegroups.com> |
On 11/10/2016 13:17, Thiago Adams wrote:
> But I think it s strange that I cannot use the same
> syntax for declarations in structs and functions.
>
> For instance:
>
> struct X
> {
> int * a[]; //ERROR
> int b[]; //ERROR
> };
>
> void f(int * a[]) { } //Ok
> void f2(int b[]) { } //Ok
>
> I was planning to use this syntax to document that for instance
>
> struct X{
> int b[];
> }
>
> b is a pointer to many ints.
>
> and
>
> int * b; would be used to document a pointer to just one int
>
> (also a tip for static analysis)
You've just discovered that C type declarations are a mess. As well as
being context sensitive.
> when I do out of function scope
>
> //warning: array 'i' assumed to have one element
> int i[];
>
> So here is one more language suggestion:
>
> make empty array syntax the same of "pointer" syntax.
>
>
> int i[]; the same of int *i;
That's going to be a problem because empty bounds are often used like this:
int i[] = {10,20,30,40};
The bounds are now determined by the compiler (4 in this example).
Requiring even that to be implemented by pointer will cause
difficulties. And a mismatch between the above and:
int j[4] = {10,20,30,40};
Here, i=0 would be legal, but not j=0;
It will also cause a mismatch (a serious one this time) when j is
declared elsewhere as:
extern int j[];
Here, you can't put in the bounds as you don't know what they are.
(You'd have to put in a misleading dummy length.)
Also, in a function:
void fn(int (*A)[]);
A has type 'pointer to unbounded array of int'. But you want [] to add
an extra pointer to result in ... ?
--
Bartc
>
>
>
Back to comp.lang.c | Previous | Next — Previous 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