Thread overview
DMC 8.31.2 error
Dec 15, 2002
Gisle Vanem
Dec 15, 2002
Richard
Dec 15, 2002
Gisle Vanem
Dec 15, 2002
Richard
Dec 15, 2002
Richard
December 15, 2002
The following code doesn't compile:

--------------------------------------
#include <stdio.h>
typedef unsigned char eth_address[6];
extern int set_addr (const eth_address *addr);

int main (void)
{
  return (0);
}
--------------------------------
Error is:
  test.c(3) : Error: type qualifiers and static can only appear in outermost array
  of function parameter

What is this? This used to be no problem.

Gisle V.

# rm /bin/laden
/bin/laden: Not found


December 15, 2002
In article <ati7lr$26qm$1@digitaldaemon.com>, Gisle Vanem says...
>
>The following code doesn't compile:
>
>--------------------------------------
>#include <stdio.h>
>typedef unsigned char eth_address[6];
>extern int set_addr (const eth_address *addr);
>
>int main (void)
>{
>  return (0);
>}

Not sure why it stopped working. I'm almost conviced that the fact that it does not work is correct. The array [6] gets converted to an unsigned char * to array element [0], then the parameter gets further defined as a pointer to a pointer to unsigned char. Now the compiler should try and make the inner array constant, but there is a rule to prevent that so you get the error. Try -

typedef unsigned char eth_address[6];
extern int set_addr (eth_address* const addr);
//extern int set_addr (const eth_address *addr);

int main (void)
{
return (0);
}

This marks the exterior "array" as constant.

I can't help wonder why your are passing a pointer to a pointer to unsigned char. The array get's converted to a pointer to unsigned char automagically with the following. Perhaps it is an external lib..

typedef unsigned char eth_address[6];
extern int set_addr (const eth_address addr);

..

// inside set_add
unsigned char* part = addr;
unsigned char* piece = addr[4];

..

Richard


December 15, 2002
"Richard" <fractal@clark.net> wrote:

> In article <ati7lr$26qm$1@digitaldaemon.com>, Gisle Vanem says...
> >
> >The following code doesn't compile:
> >
> >--------------------------------------
> >#include <stdio.h>
> >typedef unsigned char eth_address[6];
> >extern int set_addr (const eth_address *addr);
> >
> >int main (void)
> >{
> >  return (0);
> >}
>
> Not sure why it stopped working. I'm almost conviced that the fact that it does not work is correct.

It works with other compilers I've tried (bcc 4.5, gnu C 3.21, Metaware HighC 3.61, Watcom C 11 and MS Quick-C v8

>The array [6] gets converted to an unsigned char * to array
> element [0], then the parameter gets further defined as a pointer to a pointer to unsigned char. Now the compiler should try and make the inner array constant, but there is a rule to prevent that so you get the error. Try -

> typedef unsigned char eth_address[6];
> extern int set_addr (eth_address* const addr);

That worked, but is it the same? I want the '*addr' to
be const, not the 'addr' itself.

Gisle V.


December 15, 2002
In article <atijoo$2iam$1@digitaldaemon.com>, Gisle Vanem says...

>> typedef unsigned char eth_address[6];
>> extern int set_addr (eth_address* const addr);
>
>That worked, but is it the same? I want the '*addr' to
>be const, not the 'addr' itself.

Expanding the parameter out you get

unsigned char * * const addr

Which reads: addr is an ordinary pointer that is const that points to an ordinary pointer that points to unsigned char. So yes, addr is const and its value cannot be changed, but what it points to can be changed.

If you want to qualify what the array points to as const (the 6 unsigned char can't be changed) you can try:

typedef const unsigned char * eth_address;
extern int set_addr (eth_address* addr);

which reads: addr is an ordinary pointer that points to an ordinary pointer that points to const unsigned char.

Richard


December 15, 2002
This approach might suit your needs as well, but you need to lose the typedef.

extern int set_add(const unsigned char (*addr)[6]);

int set_addr(const unsigned char (*addr)[6])
{
const unsigned char *a = *addr;
return 0;
}

void main()
{
unsigned char b[6] = "12345";
set_addr(&b);

}