Attention is currently required from: arehbein.
2 comments:
File src/osmo-upf/up_session.c:
Patch Set #2, Line 124: struct osmo_sockaddr osa = {};
This (`{}`) doesn't seem to be ISO C (or I misunderstood the syntax section of the latest draft), is […]
yeah we've had some discussions on that before.
struct foo f = {};
initializes all members to zero.
It was then brought to my attention that the "normal" way to do this is:
struct foo = {0};
I find this syntax odd, because 0 is assigned to the first member of a struct, and the rest of the members get an implicit zero because they are not present. that works fine with a struct like this:
struct foo {
int first;
int second;
};
but when the struct has "nested" members the {0} syntax looks incorrrect:
struct foo {
int arr[23];
};
struct foo f = {0};
the correct way to initialize the arr member would be
struct foo f = { {0, 1, 2} };
or
struct foo f = { {0} };
Now, in many cases, just f = {0} magically works. I'm not sure whether that is special-cased by the compiler or what. So then I started to adopt the "{0}" syntax. But *then*, a while passed and i did encounter a case where i could not initialize a struct with "{0}". i don't remember in detail, but it was a nested struct, maybe like
struct foo {
struct {
struct baz memb;
} bar;
};
So I hit a case where "{0}" doesn't compile, but "{}" works without problems.
Long story short, i have now gone back to using and prefering "{}", because it simply makes more sense to me, and all compilers we encounter in osmocom seem to be fine with that.
BTW I also often use a syntax like
f = (struct foo){};
which is a memset(0). or
f = (struct foo){
.bar = {
.baz = { 1, "alpha" },
},
};
to zero-initialize the struct and place select values at the same time, avoiding a lot of repetition.
I've gotten some frowns from code review, but so far this syntax has always worked as expected.
File tests/netinst.vty:
Trailing space (if that's how it looks in Gerrit). Not sure if we care if it isn't source code...
this trailing whitespace is returned from the telnet VTY, if we fix that the test will fail. so need to keep that.
To view, visit change 30461. To unsubscribe, or for help writing mail filters, visit settings.