On 11/12/2017 09:49 PM, ros...@gmail.com wrote:
On Wed, 2017-11-08 at 21:17 +0100, Arjen de Korte wrote:
Citeren Rosen Penev <ros...@gmail.com>:
Less verbose.
And uses a GCC extension which makes it less portable. ISO C
forbids
empty initializer braces [1]. See for yourself by adding the
-pedantic
flag to your CFLAGS. The correct way to initialize to all-zeros is
therefore { 0 }.
[1] ISO/IEC 9899:201x, paragraph 6.7.9 Initialization, clause 21
"If there are fewer initializers in a brace-enclosed list than
there
are elements or members
of an aggregate, or fewer characters in a string literal used to
initialize an array of known
size than there are elements in the array, the remainder of
the aggregate shall be
initialized implicitly the same as objects that have static storage
duration."
I decided to test this with the following program.
#include <stdio.h>
#include <stdint.h>
#include <string.h>
int main()
{
struct k {
int h;
int t;
};
struct k z = {5};
printf("%d", z.t);
return 0;
}
;
0 was printed instead of 5.
This is what should happen. It doesn't repeat a pattern. To rephrase
ISO-C standard. If the implied initialization of COMMON or weak
definitions is 0, then partial initialization will initialize forgotten
elements to 0. As a consequence one quality check done in some
organizations is expect: {0} only, maybe require curls representing
nested depth, or all elements explicitly initialized, else any other is
rejected.
- Eric
_______________________________________________
Lede-dev mailing list
Lede-dev@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/lede-dev