Source-Changes-D archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: CVS commit: src/sys/dev/usb
On Sat, Apr 21, 2018 at 05:09:27PM +0300, Valery Ushakov wrote:
> On Sat, Apr 21, 2018 at 09:44:59 +0200, Manuel Bouyer wrote:
> > Date: Sat, 21 Apr 2018 09:44:59 +0200
> > From: Manuel Bouyer <bouyer%antioche.eu.org@localhost>
> > Subject: Re: CVS commit: src/sys/dev/usb
> > To: Martin Husemann <martin%duskware.de@localhost>
> > Cc: Christos Zoulas <christos%astron.com@localhost>, source-changes-d%NetBSD.org@localhost
> >
> > On Sat, Apr 21, 2018 at 09:37:46AM +0200, Martin Husemann wrote:
> > > On Sat, Apr 21, 2018 at 09:30:20AM +0200, Manuel Bouyer wrote:
> > > > > >
> > > > > >- axe_cmd(sc, AXE_CMD_WRITE_MCAST, 0, 0, (void *)&hashtbl);
> > > > > >+ axe_cmd(sc, AXE_CMD_WRITE_MCAST, 0, 0, hashtbl);
> > > > > >
> > > > > >missing & ?
> > > > >
> > > > > uint8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
> > > >
> > > > So I guess the code was wrong before; not sure how multicast could have
> > > > worked.
> > >
> > > No, the address is only needed as rhs of the cast. If passed directly,
> > > the address will be used (due to arrays being passed as pointer to first
> > > element in C).
> > >
> > > Try it:
> > >
> > > #include <stdio.h>
> > > #include <inttypes.h>
> > >
> > > int main(void)
> > > {
> > > static uint8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
> > >
> > > printf("%p vs %p\n", (void *)&hashtbl, hashtbl);
> > > return 0;
> > > }
> >
> > I didn't know this. hashtbl and &hashtbl[0] are equivalent, and I would
> > assume that &hashtbl is always a pointer to pointer. So the behavior depends
> > on hashtbl being declared as pointer or as array ?
> > this is confusing ...
>
> &hashtbl is a pointer to an array of size 8. You can see this with
> pointer arithmetic:
>
> char hashtbl[8];
> printf("%p %p\n%p %p\n", hashtbl, hashtbl + 1, &hashtbl, &hashtbl + 1);
>
> prints
>
> 0x7fff54e4b720 0x7fff54e4b721
> 0x7fff54e4b720 0x7fff54e4b728
Yes, what's confusing is that in this case hashtbl and &hashtbl are
the same thing, while for
char *hashtbl;
they are different objects.
--
Manuel Bouyer <bouyer%antioche.eu.org@localhost>
NetBSD: 26 ans d'experience feront toujours la difference
--
Home |
Main Index |
Thread Index |
Old Index