[haiku-commits] Re: haiku: hrev45465 - src/add-ons/kernel/drivers/network/usb_asix

  • From: Alexander von Gluck IV <kallisti5@xxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 09 Apr 2013 19:14:56 -0500

On 04/09/2013 7:04 pm, Alexander von Gluck IV wrote:
On 04/09/2013 4:56 pm, Ingo Weinhold wrote:
On 04/09/2013 11:47 PM, Philippe Houdoin wrote:
It does add another, uninitialized, item to the array, which will lead
to potential error regarding sizeof().
That was the issue behind #5929, for instance.
http://dev.haiku-os.org/ticket/5929
There you actually removed an element. Here it's just about the
trailing comma which is ignored by the compiler.

+1.

I did it because it makes managing large lists of items easier without
needing to add unchanged lines into the diff of piece of code.

The dangling , is ignored by the compiler.

Here is some proof to back up this wild and crazy claim :)


#include <stdio.h>

struct stuff {
    int this;
    int that;
};

struct stuff gStuff1[] = {
    {0, 0},
    {1, 1},
    {2, 2}
};

struct stuff gStuff2[] = {
    {0, 0},
    {1, 1},
    {2, 2},
};

int
main()
{
    printf("gStuff1: %d\n", sizeof(gStuff1) / sizeof(gStuff1[0]));
    printf("gStuff2: %d\n", sizeof(gStuff2) / sizeof(gStuff2[0]));
    return 0;
}


Other related posts: