T
Trond Norbye
Hi,
I get some warnings when I use -Wmissing-field-initializers and I
really don't understand them.
#include <stdint.h>
typedef union {
struct {
uint8_t magic;
uint8_t opcode;
} request;
uint8_t bytes[2];
} request_header;
typedef union {
struct {
request_header header;
} message;
uint8_t bytes[sizeof(request_header)];
} request_message;
int main(int argc, char **argv)
{
request_message request = {
.message.header.request.magic = 0,
};
return 0;
}
trond@storm> /opt/gcc/bin/gcc -c test.c -Wmissing-field-initializers
test.c: In function ‘main’:
test.c:22: warning: missing initializer
test.c:22: warning: (near initialization for
‘request.message.header.request.opcode’)
trond@storm> /opt/gcc/bin/gcc --version
gcc (GCC) 4.4.0
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There
is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
If I change the initialization to:
request_message request = {
.message.header.request= {
.magic = 0,
}
};
It compiles without warnings.
English is not my native language, so I might have parsed section
6.7.8 in C99 wrong. Is the syntax I'm using wrong, or could this be a
bug in -Wmissing-field-initializers?
According to the manual for -Wmissing-field-initializers it should
give a warning for designated initiators (and that's what I'm
using...).
Cheers,
Trond
I get some warnings when I use -Wmissing-field-initializers and I
really don't understand them.
#include <stdint.h>
typedef union {
struct {
uint8_t magic;
uint8_t opcode;
} request;
uint8_t bytes[2];
} request_header;
typedef union {
struct {
request_header header;
} message;
uint8_t bytes[sizeof(request_header)];
} request_message;
int main(int argc, char **argv)
{
request_message request = {
.message.header.request.magic = 0,
};
return 0;
}
trond@storm> /opt/gcc/bin/gcc -c test.c -Wmissing-field-initializers
test.c: In function ‘main’:
test.c:22: warning: missing initializer
test.c:22: warning: (near initialization for
‘request.message.header.request.opcode’)
trond@storm> /opt/gcc/bin/gcc --version
gcc (GCC) 4.4.0
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There
is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
If I change the initialization to:
request_message request = {
.message.header.request= {
.magic = 0,
}
};
It compiles without warnings.
English is not my native language, so I might have parsed section
6.7.8 in C99 wrong. Is the syntax I'm using wrong, or could this be a
bug in -Wmissing-field-initializers?
According to the manual for -Wmissing-field-initializers it should
give a warning for designated initiators (and that's what I'm
using...).
Cheers,
Trond