Connecting Tech Pros Worldwide Help | Site Map

Initializing Pointer to an array

rupesh_533@rediffmail.com
Guest
 
Posts: n/a
#1: Nov 15 '05
I am assuming the following things.
1.Pointer to an integer means it points to an integer,On incrementing
the pointer,it points to the next integer in memory.
2.Pointer to an array of some size means it points to an array,On
incrementing the pointer,it should point to next array of that size.

Correct me if i am wrong.
We declare a pointer to an integer array of Size N as
int (*a)[N];

Now My Problem is
I have an array of 100 Integers,Pointer to an array of 10 integers
int (*a)[10];
int b[100];
How can i initialize the pointer a to point to the array b base
address.

rupesh_533@rediffmail.com
Guest
 
Posts: n/a
#2: Nov 15 '05

re: Initializing Pointer to an array


I am able to initialize the pointer to the array as
int (*a)[10];
int b[100];

a = &b[0];
But i am getting the warning
warning: assignment from incompatible pointer type

My Code is
int main()
{
int (*a)[10];
int b[100];
int i;

for(i=0;i<100;i++)
b[i]=i;

a = &b[0];

printf(" %u %u %d %d\n",a ,&b[0],**a,b[0]);
a++;
printf(" %u %u %d %d\n",a ,&b[10],**a,b[10]);
a++;
printf(" %u %u %d %d\n",a , &b[20],**a,b[20]);
a++;
printf(" %u %u %d %d\n",a , &b[30],**a,b[30]);
}

I am getting correct results as
3221219184 3221219184 0 0
3221219224 3221219224 10 10
3221219264 3221219264 20 20
3221219304 3221219304 30 30

Christopher Benson-Manica
Guest
 
Posts: n/a
#3: Nov 15 '05

re: Initializing Pointer to an array


rupesh_533@rediffmail.com wrote:
[color=blue]
> I am able to initialize the pointer to the array as
> int (*a)[10];
> int b[100];[/color]
[color=blue]
> a = &b[0];
> But i am getting the warning
> warning: assignment from incompatible pointer type[/color]

Of course you are. a is a pointer to an array of 10 ints (which
you probably do not need), while &b[0] is a pointer to an int. Your
compiler is doing you a favor.
[color=blue]
> My Code is
> int main()[/color]

int main( void ) /* better */
[color=blue]
> {
> int (*a)[10];
> int b[100];
> int i;[/color]
[color=blue]
> for(i=0;i<100;i++)[/color]

for( i=0; i < sizeof b; i++) /* better */
[color=blue]
> b[i]=i;[/color]
[color=blue]
> a = &b[0];[/color]

Wrong, as I said.
[color=blue]
> printf(" %u %u %d %d\n",a ,&b[0],**a,b[0]);[/color]

Wrong in multiple ways:

1) You did not include <stdio.h>.
2) %u is not the conversion specifier you want for pointers.

printf( " %p %p %d %d\n", (void*)a, (void*)&b[0], **a, b[0] );

Note the casts; they are required.
[color=blue]
> a++;
> printf(" %u %u %d %d\n",a ,&b[10],**a,b[10]);
> a++;
> printf(" %u %u %d %d\n",a , &b[20],**a,b[20]);
> a++;
> printf(" %u %u %d %d\n",a , &b[30],**a,b[30]);[/color]

Unless you are using a C99 compiler, you must return a value from
main(). Your compiler should have warned you about this unfortunate
omission.
[color=blue]
> }[/color]

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Antonio Contreras
Guest
 
Posts: n/a
#4: Nov 15 '05

re: Initializing Pointer to an array


Christopher Benson-Manica wrote:

<snipped rest of code>
[color=blue]
> rupesh_533@rediffmail.com wrote:[color=green]
> > int main()[/color]
>
> int main( void ) /* better */
>[color=green]
> > {
> > int (*a)[10];
> > int b[100];
> > int i;[/color]
>[color=green]
> > for(i=0;i<100;i++)[/color]
>
> for( i=0; i < sizeof b; i++) /* better */
>[/color]

Shouldn't that be:
for (i = 0; i < ((sizeof b) / (sizeof int)); i++)
??

Christopher Benson-Manica
Guest
 
Posts: n/a
#5: Nov 15 '05

re: Initializing Pointer to an array


Antonio Contreras <anconor@gmail.com> wrote:
[color=blue]
> for (i = 0; i < ((sizeof b) / (sizeof int)); i++)[/color]

Yes. Ouch. (And thank you.)

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Flash Gordon
Guest
 
Posts: n/a
#6: Nov 15 '05

re: Initializing Pointer to an array


Christopher Benson-Manica wrote:[color=blue]
> Antonio Contreras <anconor@gmail.com> wrote:
>[color=green]
>>for (i = 0; i < ((sizeof b) / (sizeof int)); i++)[/color]
>
> Yes. Ouch. (And thank you.)[/color]

Or better yet:
for (i = 0; i < ((sizeof b) / (sizeof *b)); i++)

Then it will compile (apart from being incomplete and the certainty of
me introducing an error in my correction) and be independant of the type
of array b.

:-)
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Antonio Contreras
Guest
 
Posts: n/a
#7: Nov 15 '05

re: Initializing Pointer to an array


Flash Gordon wrote:[color=blue]
> Christopher Benson-Manica wrote:[color=green]
> > Antonio Contreras <anconor@gmail.com> wrote:
> >[color=darkred]
> >>for (i = 0; i < ((sizeof b) / (sizeof int)); i++)[/color]
> >
> > Yes. Ouch. (And thank you.)[/color]
>
> Or better yet:
> for (i = 0; i < ((sizeof b) / (sizeof *b)); i++)
>
> Then it will compile (apart from being incomplete and the certainty of
> me introducing an error in my correction) and be independant of the type
> of array b.
>
> :-)[/color]

Well, for purely aesthetic reasons I would prefer the totally
equivalent:

for (i = 0; i < ((sizeof b) / (sizeof b[0])); i++)

Call me paranoid, but the equivalence between arrays and pointers is
confusing enough [1] without dereferencing pointers that have been
created by the decay of an array name.

[1] Actually I've gotten used to it and it's not confusing anymore, but
it was really confusing two years ago.

Peter Nilsson
Guest
 
Posts: n/a
#8: Nov 15 '05

re: Initializing Pointer to an array


Christopher Benson-Manica wrote:[color=blue]
>
> Unless you are using a C99 compiler, you must return a value from
> main().[/color]

It's not mandatory un C90, just desirable.
[color=blue]
> Your compiler should have warned you about this unfortunate
> omission.[/color]

Perhaps, but unlike C++, both C90 and C99 allow non-void functions to
fail
to return a value. So long as the calling function doesn't attempt to
use
the value, all is fine.

As this is a <cough> feature of the language, many old compilers won't
issue a warning for this.

--
Peter

Michael Wojcik
Guest
 
Posts: n/a
#9: Nov 15 '05

re: Initializing Pointer to an array



In article <1129815915.487101.110370@g44g2000cwa.googlegroups .com>, "Antonio Contreras" <anconor@gmail.com> writes:[color=blue]
> Christopher Benson-Manica wrote:[color=green]
> > rupesh_533@rediffmail.com wrote:[color=darkred]
> > > int (*a)[10];
> > > int b[100];
> > > int i;[/color]
> >[color=darkred]
> > > for(i=0;i<100;i++)[/color]
> >
> > for( i=0; i < sizeof b; i++) /* better */[/color]
>
> Shouldn't that be:
> for (i = 0; i < ((sizeof b) / (sizeof int)); i++)[/color]

When the sizeof operator is applied to a type, the name of the type
must be parenthesized. You're missing parentheses around "int"
(which is ironic, considering all the unnecessary sets of parentheses
you have there).

What would be better is

for (i = 0; i < sizeof b / sizeof *b; i++)

which works for a "b" of any (complete) array type.

--
Michael Wojcik michael.wojcik@microfocus.com

Global warming is just a theory. This is Intelligent Defrosting. -- "Gregg"
Jack Klein
Guest
 
Posts: n/a
#10: Nov 15 '05

re: Initializing Pointer to an array


On 20 Oct 2005 15:36:14 -0700, "Antonio Contreras" <anconor@gmail.com>
wrote in comp.lang.c:
[color=blue]
> Flash Gordon wrote:[color=green]
> > Christopher Benson-Manica wrote:[color=darkred]
> > > Antonio Contreras <anconor@gmail.com> wrote:
> > >
> > >>for (i = 0; i < ((sizeof b) / (sizeof int)); i++)
> > >
> > > Yes. Ouch. (And thank you.)[/color]
> >
> > Or better yet:
> > for (i = 0; i < ((sizeof b) / (sizeof *b)); i++)
> >
> > Then it will compile (apart from being incomplete and the certainty of
> > me introducing an error in my correction) and be independant of the type
> > of array b.
> >
> > :-)[/color]
>
> Well, for purely aesthetic reasons I would prefer the totally
> equivalent:
>
> for (i = 0; i < ((sizeof b) / (sizeof b[0])); i++)
>
> Call me paranoid, but the equivalence between arrays and pointers is
> confusing enough [1] without dereferencing pointers that have been
> created by the decay of an array name.[/color]

The sizeof operator never evaluates the value of its operand in C
prior to C99, and only to determine the size of a variable length
array in C99. Under no circumstances does sizeof dereference a
pointer given to it as an argument.

Plus the C language absolutely requires that the expression b[0] be
evaluated as if written *b, so the Christopher's code and your
alternative are exactly equivalent in C.
[color=blue]
> [1] Actually I've gotten used to it and it's not confusing anymore, but
> it was really confusing two years ago.[/color]

In either case, there is no evaluation of the value of b[0] or *b, and
no dereference.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Christopher Benson-Manica
Guest
 
Posts: n/a
#11: Nov 15 '05

re: Initializing Pointer to an array


Peter Nilsson <airia@acay.com.au> wrote:
[color=blue]
> It's not mandatory un C90, just desirable.[/color]

I suppose that's strictly correct, but it's probably safe to assume
that a reasonable host environment will attempt to use the termination
status of main. I would think that the chances of UB on a hosted
implentation would be rather high.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Zara
Guest
 
Posts: n/a
#12: Nov 15 '05

re: Initializing Pointer to an array


On Fri, 21 Oct 2005 14:34:06 +0000 (UTC), Christopher Benson-Manica
<ataru@nospam.cyberspace.org> wrote:
[color=blue]
>Peter Nilsson <airia@acay.com.au> wrote:
>[color=green]
>> It's not mandatory un C90, just desirable.[/color]
>
>I suppose that's strictly correct, but it's probably safe to assume
>that a reasonable host environment will attempt to use the termination
>status of main. I would think that the chances of UB on a hosted
>implentation would be rather high.[/color]

C *and* C++ specify that reaching the the terminating } of main() will
return 0; so this function *always* return a valid value.
Christopher Benson-Manica
Guest
 
Posts: n/a
#13: Nov 15 '05

re: Initializing Pointer to an array


Zara <nospam.yozara@terra.es> wrote:
[color=blue]
> C *and* C++ specify that reaching the the terminating } of main() will
> return 0; so this function *always* return a valid value.[/color]

C89 does not.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Flash Gordon
Guest
 
Posts: n/a
#14: Nov 15 '05

re: Initializing Pointer to an array


Christopher Benson-Manica wrote:[color=blue]
> Zara <nospam.yozara@terra.es> wrote:
>[color=green]
>>C *and* C++ specify that reaching the the terminating } of main() will
>>return 0; so this function *always* return a valid value.[/color]
>
> C89 does not.[/color]

And, just to emphasise the point, there are far more people using
implementations that can support C89 correctly (modulo bugs) than there
are people using conforming C99 implementations. For a start, neither
gcc nor MS VC++ fully support C99 but both fully support C89 (modulo bugs).
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Tim Rentsch
Guest
 
Posts: n/a
#15: Nov 15 '05

re: Initializing Pointer to an array


Jack Klein <jackklein@spamcop.net> writes:
[color=blue]
> Plus the C language absolutely requires that the expression b[0] be
> evaluated as if written *b,[/color]

Usually but not always.

void
foo(){
int a[10];
int (*b)[] = &a;
int *c;

c = b[0]; /* this doesn't work */
c = *b; /* this works */
}

Personally, I'd be in favor of adding a rule that makes the two
forms equivalent in the case of a 0-valued constant expression.
But that's another story.

Antonio Contreras
Guest
 
Posts: n/a
#16: Nov 15 '05

re: Initializing Pointer to an array


Jack Klein wrote:[color=blue]
> On 20 Oct 2005 15:36:14 -0700, "Antonio Contreras" <anconor@gmail.com>
> wrote in comp.lang.c:
>[color=green]
> > Flash Gordon wrote:[color=darkred]
> > > Christopher Benson-Manica wrote:
> > > > Antonio Contreras <anconor@gmail.com> wrote:
> > > >
> > > >>for (i = 0; i < ((sizeof b) / (sizeof int)); i++)
> > > >
> > > > Yes. Ouch. (And thank you.)
> > >
> > > Or better yet:
> > > for (i = 0; i < ((sizeof b) / (sizeof *b)); i++)
> > >
> > > Then it will compile (apart from being incomplete and the certainty of
> > > me introducing an error in my correction) and be independant of the type
> > > of array b.
> > >
> > > :-)[/color]
> >
> > Well, for purely aesthetic reasons I would prefer the totally
> > equivalent:
> >
> > for (i = 0; i < ((sizeof b) / (sizeof b[0])); i++)
> >
> > Call me paranoid, but the equivalence between arrays and pointers is
> > confusing enough [1] without dereferencing pointers that have been
> > created by the decay of an array name.[/color]
>
> The sizeof operator never evaluates the value of its operand in C
> prior to C99, and only to determine the size of a variable length
> array in C99. Under no circumstances does sizeof dereference a
> pointer given to it as an argument.[/color]

I didn't imply that. What I tried to say is that it "looks" like it,
and that it is confusing when you're learning C. IMHO, given that b is
an array, b[0] is less confusing than *b.
[color=blue]
> Plus the C language absolutely requires that the expression b[0] be
> evaluated as if written *b, so the Christopher's code and your
> alternative are exactly equivalent in C.[/color]

I acknowledge that much. I literally said "I prefer the _totally
equivalent_..."
[color=blue][color=green]
> > [1] Actually I've gotten used to it and it's not confusing anymore, but
> > it was really confusing two years ago.[/color]
>
> In either case, there is no evaluation of the value of b[0] or *b, and
> no dereference.[/color]

Again, I didn't try to imply that. I guess it was a really bad wording
from my side.

Barry Schwarz
Guest
 
Posts: n/a
#17: Nov 15 '05

re: Initializing Pointer to an array


On 21 Oct 2005 12:22:00 -0700, Tim Rentsch <txr@alumnus.caltech.edu>
wrote:
[color=blue]
>Jack Klein <jackklein@spamcop.net> writes:
>[color=green]
>> Plus the C language absolutely requires that the expression b[0] be
>> evaluated as if written *b,[/color]
>
>Usually but not always.
>
> void
> foo(){
> int a[10];
> int (*b)[] = &a;
> int *c;
>
> c = b[0]; /* this doesn't work */
> c = *b; /* this works */[/color]

Are you sure? n1124 states in 6.5.2.1(2) that

A postfix expression followed by an expression in square brackets []
is a subscripted designation of an element of an array object. The
definition of the subscript operator [] is that E1[E2] is identical to
(*((E1)+(E2))). Because of the conversion rules that apply to the
binary + operator, if E1 is an array object (equivalently, a pointer
to the initial element of an array object) and E2 is an integer,
E1[E2] designates the E2-th element of E1 (counting from zero).

So b[0] is the same as *(b+0) which is the same as *b. Both
expressions should evaluate to the address of a with type array of 10
int which, since it is not one of the exceptions, will then be
converted to the address of a[0] with type pointer to int.
[color=blue]
> }
>
>Personally, I'd be in favor of adding a rule that makes the two
>forms equivalent in the case of a 0-valued constant expression.
>But that's another story.[/color]


<<Remove the del for email>>
S.Tobias
Guest
 
Posts: n/a
#18: Nov 15 '05

re: Initializing Pointer to an array


Barry Schwarz <schwarzb@deloz.net> wrote:[color=blue]
> On 21 Oct 2005 12:22:00 -0700, Tim Rentsch <txr@alumnus.caltech.edu>
> wrote:[color=green]
>>Jack Klein <jackklein@spamcop.net> writes:
>>[color=darkred]
>>> Plus the C language absolutely requires that the expression b[0] be
>>> evaluated as if written *b,[/color]
>>
>>Usually but not always.
>>
>> void
>> foo(){
>> int a[10];
>> int (*b)[] = &a;
>> int *c;
>>
>> c = b[0]; /* this doesn't work */
>> c = *b; /* this works */[/color]
>
> Are you sure? n1124 states in 6.5.2.1(2) that
>
> A postfix expression followed by an expression in square brackets []
> is a subscripted designation of an element of an array object. The
> definition of the subscript operator [] is that E1[E2] is identical to
> (*((E1)+(E2))). Because of the conversion rules that apply to the
> binary + operator, if E1 is an array object (equivalently, a pointer
> to the initial element of an array object) and E2 is an integer,
> E1[E2] designates the E2-th element of E1 (counting from zero).
>
> So b[0] is the same as *(b+0) which is the same as *b.[/color]

They are not the same. `b+0' has an additional constraint:
6.5.6#2
# [#2] For addition, either both operands shall have
# arithmetic type, or one operand shall be a pointer to an
# object type and the other shall have integer type.

("Object type" is a complete type.)
[color=blue]
>Both
> expressions should evaluate to the address of a with type array of 10
> int which,[/color]

`*b' is an incomplete (array) type lvalue.
[color=blue]
>since it is not one of the exceptions, will then be
> converted to the address of a[0] with type pointer to int.[/color]

Yes.

--
Stan Tobias
mailx `echo siXtY@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`
Flash Gordon
Guest
 
Posts: n/a
#19: Nov 15 '05

re: Initializing Pointer to an array


S.Tobias wrote:[color=blue]
> Barry Schwarz <schwarzb@deloz.net> wrote:
>[color=green]
>>On 21 Oct 2005 12:22:00 -0700, Tim Rentsch <txr@alumnus.caltech.edu>
>>wrote:
>>[color=darkred]
>>>Jack Klein <jackklein@spamcop.net> writes:
>>>
>>>
>>>>Plus the C language absolutely requires that the expression b[0] be
>>>>evaluated as if written *b,
>>>
>>>Usually but not always.
>>>
>>> void
>>> foo(){
>>> int a[10];
>>> int (*b)[] = &a;
>>> int *c;
>>>
>>> c = b[0]; /* this doesn't work */
>>> c = *b; /* this works */[/color]
>>
>>Are you sure? n1124 states in 6.5.2.1(2) that
>>
>>A postfix expression followed by an expression in square brackets []
>>is a subscripted designation of an element of an array object. The
>>definition of the subscript operator [] is that E1[E2] is identical to
>>(*((E1)+(E2))). Because of the conversion rules that apply to the
>>binary + operator, if E1 is an array object (equivalently, a pointer
>>to the initial element of an array object) and E2 is an integer,
>>E1[E2] designates the E2-th element of E1 (counting from zero).
>>
>>So b[0] is the same as *(b+0) which is the same as *b.[/color]
>
>
> They are not the same. `b+0' has an additional constraint:
> 6.5.6#2
> # [#2] For addition, either both operands shall have
> # arithmetic type, or one operand shall be a pointer to an
> # object type and the other shall have integer type.
>
> ("Object type" is a complete type.)[/color]

Yes.
[color=blue][color=green]
>>Both
>>expressions should evaluate to the address of a with type array of 10
>>int which,[/color]
>
> `*b' is an incomplete (array) type lvalue.[/color]

*b being an incomplete type is irrelevant since it is *(b+0) NOT *b +0
so 0 is added to b not to *b.
[color=blue][color=green]
>>since it is not one of the exceptions, will then be
>>converted to the address of a[0] with type pointer to int.[/color]
>
> Yes.[/color]
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
S.Tobias
Guest
 
Posts: n/a
#20: Nov 15 '05

re: Initializing Pointer to an array


Flash Gordon <spam@flash-gordon.me.uk> wrote:[color=blue]
> S.Tobias wrote:[color=green]
>> Barry Schwarz <schwarzb@deloz.net> wrote:[color=darkred]
>>>On 21 Oct 2005 12:22:00 -0700, Tim Rentsch <txr@alumnus.caltech.edu>
>>>wrote:[/color][/color][/color]
[color=blue][color=green][color=darkred]
>>>> void
>>>> foo(){
>>>> int a[10];
>>>> int (*b)[] = &a;
>>>> int *c;
>>>>
>>>> c = b[0]; /* this doesn't work */
>>>> c = *b; /* this works */[/color][/color][/color]

[snip][color=blue][color=green][color=darkred]
>>>So b[0] is the same as *(b+0) which is the same as *b.[/color][/color][/color]
....[color=blue][color=green][color=darkred]
>>>Both
>>>expressions should evaluate to the address of a with type array of 10
>>>int which,[/color]
>>
>> `*b' is an incomplete (array) type lvalue.[/color]
>
> *b being an incomplete type is irrelevant since it is *(b+0) NOT *b +0
> so 0 is added to b not to *b.
>[/color]
Right. I did mean `*b', but I misunderstood what Barry had said, so my
answer was irrelevant, too.

One more try: `*b' evaluates to an incomplete array type lvalue
for the array `a', which is immediately converted to the pointer to
the first element of `a' (not: "to the address of `a'"; unless "address"
is understood as "location").

--
Stan Tobias
mailx `echo siXtY@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`
Peter Nilsson
Guest
 
Posts: n/a
#21: Nov 15 '05

re: Initializing Pointer to an array


Christopher Benson-Manica wrote:[color=blue]
> Peter Nilsson <airia@acay.com.au> wrote:[/color]
[[color=blue][color=green][color=darkred]
> > > Unless you are using a C99 compiler, you must return a value from
> > > main().[/color][/color][/color]
][color=blue][color=green]
> > It's not mandatory un C90, just desirable.[/color]
>
> I suppose that's strictly correct, but it's probably safe to assume
> that a reasonable host environment will attempt to use the termination
> status of main.[/color]

It's not safe to assume that, but it is something to consider.
[color=blue]
> I would think that the chances of UB on a hosted
> implentation would be rather high.[/color]

The standard doesn't define what the host does with an undefined
status.
But it doesn't define what the host does with a successful status
either.

Hence, if one is 'UB', so is the other!

Pragmatically though, programmers who leave out the return value from
main under C89 are risking future problems in cases where their program
is used in higher level script (e.g. shell script). Such scripting
languages may terminate on spurious error signals from the program.

So 'UB' in this case is probably better phrased as undesirable
behaviour,
rather than undefined.

--
Peter

Tim Rentsch
Guest
 
Posts: n/a
#22: Nov 15 '05

re: Initializing Pointer to an array


Barry Schwarz <schwarzb@deloz.net> writes:
[color=blue]
> On 21 Oct 2005 12:22:00 -0700, Tim Rentsch <txr@alumnus.caltech.edu>
> wrote:
>[color=green]
> >Jack Klein <jackklein@spamcop.net> writes:
> >[color=darkred]
> >> Plus the C language absolutely requires that the expression b[0] be
> >> evaluated as if written *b,[/color]
> >
> >Usually but not always.
> >
> > void
> > foo(){
> > int a[10];
> > int (*b)[] = &a;
> > int *c;
> >
> > c = b[0]; /* this doesn't work */
> > c = *b; /* this works */[/color]
>
> Are you sure? n1124 states in 6.5.2.1(2) that
>
> A postfix expression followed by an expression in square brackets []
> is a subscripted designation of an element of an array object. The
> definition of the subscript operator [] is that E1[E2] is identical to
> (*((E1)+(E2))). Because of the conversion rules that apply to the
> binary + operator, if E1 is an array object (equivalently, a pointer
> to the initial element of an array object) and E2 is an integer,
> E1[E2] designates the E2-th element of E1 (counting from zero).
>
> So b[0] is the same as *(b+0) which is the same as *b. Both
> expressions should evaluate to the address of a with type array of 10
> int which, since it is not one of the exceptions, will then be
> converted to the address of a[0] with type pointer to int.[/color]

I gather this has been said already, but briefly:

The equivalence holds, but a requirement for the + operator
is that a pointer operand be a pointer to an object type
(ie, rather than a pointer to an incomplete type). The
variable 'b' is a pointer to an incomplete type, and so
there is a constraint violation.
Closed Thread