Re: Why the compiler gives warning ?



junky_fellow@xxxxxxxxxxx wrote:
> N869, Page 47,
>
> "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 is not an lvalue."
>
> Now, consider following piece of code,
>
> char arr[10]; /* (line 1) */
> char (*arr_ptr)[10]; /* (line 2) */
> arr_ptr = &arr; /* (line 3) */
>
> &arr should have type, pointer to array of 10 chars. But, on
> compilation I get the following errors.
>
> 1) In this statement, & before array "arr" is ignored.
> 2) In this statement, the referenced type of the pointer
> value "&arr" is "signed char", which is not compatible
> with "array [3] of signed char".
>
> Why "line 3" is giving the above warnings ? arr_ptr and &arr
> both have the same types.

Are you using a pre-ansi C compiler? Such compilers might generate
these types of warnings, see FAQ 6.12.

Robert Gamble

.



Relevant Pages

  • Why the compiler gives warning ?
    ... "Except when it is the operand of the sizeof operator or the unary & ... initial element of the array object and is not an lvalue." ... & before array "arr" is ignored. ... the referenced type of the pointer ...
    (comp.lang.c)
  • Re: Why the compiler gives warning ?
    ... > "Except when it is the operand of the sizeof operator or the unary & ... > initial element of the array object and is not an lvalue." ... pointer to array of 10 chars. ... > compilation I get the following errors. ...
    (comp.lang.c)
  • Re: Why the compiler gives warning ?
    ... > "Except when it is the operand of the sizeof operator or the unary & ... > initial element of the array object and is not an lvalue." ... pointer to array of 10 chars. ... > compilation I get the following errors. ...
    (comp.lang.c)
  • 64 bit porting
    ... compiler and fixed all the compilation warnings. ... OFFSET macro will create problems when the structe has longs ... memory and ptr can be used as an array of two elements. ... pointer is 8 bytes and int is 4 bytes. ...
    (comp.lang.c)
  • Re: function pointers as function parameters
    ... >>> pointer to ffto fwith the result that f ... > then it would be a valid operand of the sizeof operator. ... It is a very similar argument to that for array names. ...
    (comp.lang.c)