Reputation: 11
Compiler is a GCC under MPLAB 8, dsPIC33 ver 3.30c
// Note: the first block below generates no error's with the compiler, but the data
// in the structurer is wrong.
// the 2nd block give warning, but the data is correct... why??
// NMEA2000.c:289: warning: missing braces around initializer
// NMEA2000.c:289: warning: (near initialization for 'static_can_filter[0]')
const tSCF static_can_filter[] = {
{(uint32) 0x01FFFFFF}, {(uint8) 2}, // Filter 0 (Process data)
{(uint32) 0x00000000}, {(uint8) 2}, // Filter 1
{(uint32) 0x00000000}, {(uint8) 2}, // Filter 2 (receive P2P-Message)
{(uint32) 0x0000FF00}, {(uint8) 2}, // Filter 3 (receive P2P-Message)
{(uint32) 0x00000000}, {(uint8) 2}, // Filter 4
{(uint32) 0x00000000}, {(uint8) 2}, // Filter 5
{(uint32) 0x00000000}, {(uint8) 2}, // Filter 6
{(uint32) 0x00000000}, {(uint8) 2}, // Filter 7
{(uint32) 0x00000000}, {(uint8) 2}, // Filter 8
{(uint32) 0x00000000}, {(uint8) 2}, // Filter 9
{(uint32) 0x00000000}, {(uint8) 2}, // Filter 10
{(uint32) 0x00000000}, {(uint8) 2}, // Filter 11
{(uint32) 0x00000000}, {(uint8) 2}, // Filter 12
{(uint32) 0x00000000}, {(uint8) 2}, // Filter 13
{(uint32) 0x00000000}, {(uint8) 2}, // Filter 14
(uint32) 0x00000000}, {(uint8) 2} // Filter 15
};
const tSCF static_can_filter[] = {
(uint32) 0x01FFFFFF, (uint8) 2, // Filter 0 (Process data)
(uint32) 0x00000000, (uint8) 2, // Filter 1
(uint32) 0x00000000, (uint8) 2, // Filter 2 (receive P2P-Message)
(uint32) 0x0000FF00, (uint8) 2, // Filter 3 (receive P2P-Message)
(uint32) 0x00000000, (uint8) 2, // Filter 4
(uint32) 0x00000000, (uint8) 2, // Filter 5
(uint32) 0x00000000, (uint8) 2, // Filter 6
(uint32) 0x00000000, (uint8) 2, // Filter 7
(uint32) 0x00000000, (uint8) 2, // Filter 8
(uint32) 0x00000000, (uint8) 2, // Filter 9
(uint32) 0x00000000, (uint8) 2, // Filter 10
(uint32) 0x00000000, (uint8) 2, // Filter 11
(uint32) 0x00000000, (uint8) 2, // Filter 12
(uint32) 0x00000000, (uint8) 2, // Filter 13
(uint32) 0x00000000, (uint8) 2, // Filter 14
(uint32) 0x00000000, (uint8) 2 // Filter 15
};
Upvotes: 0
Views: 15375
Reputation: 3069
Assuming tSCF is defined something like the following:
typedef struct tSCF {
uint32 a;
uint8 b;
} tSCF;
What you want probably looks like the following:
const tSCF static_can_filter[] = {
{ (uint32) 0x01FFFFFF, (uint8) 2 }, // Filter 0 (Process data)
{ (uint32) 0x00000000, (uint8) 2 }, // Filter 1
[...]
Each initializer with braces initializes a different element of the array. The first form from your question {(uint32) 0x01FFFFFF}, {(uint8) 2},
ends up building two members of the array (each with a
set to the given value, and b
set to zero). You can see this with your example by adding an explicit array bound (which will lead to the compiler complaining about excess initializers.
The second form from your question does exactly what you want it to: when there aren't any braces and the array element is a struct, the values get assigned to successive fields. There's an optional warning here (probably turned on with -Wall
or something like that) because the form given in this answer makes your intent a bit clearer.
Upvotes: 4
Reputation: 6339
Probably an unclosed brace higher up in the file... we need to see this in context - put in a file on it's own, your second array compiles just fine. I changed the types using find-and-replace, and this produces no errors or warnings with
gcc -c -Wall -Wextra
So, the error must be somewhere else.
#include <stdint.h>
const uint32_t static_can_filter[] = {
(uint32_t) 0x01FFFFFF, (uint8_t) 2, // Filter 0 (Process data)
(uint32_t) 0x00000000, (uint8_t) 2, // Filter 1
(uint32_t) 0x00000000, (uint8_t) 2, // Filter 2 (receive P2P-Message)
(uint32_t) 0x0000FF00, (uint8_t) 2, // Filter 3 (receive P2P-Message)
(uint32_t) 0x00000000, (uint8_t) 2, // Filter 4
(uint32_t) 0x00000000, (uint8_t) 2, // Filter 5
(uint32_t) 0x00000000, (uint8_t) 2, // Filter 6
(uint32_t) 0x00000000, (uint8_t) 2, // Filter 7
(uint32_t) 0x00000000, (uint8_t) 2, // Filter 8
(uint32_t) 0x00000000, (uint8_t) 2, // Filter 9
(uint32_t) 0x00000000, (uint8_t) 2, // Filter 10
(uint32_t) 0x00000000, (uint8_t) 2, // Filter 11
(uint32_t) 0x00000000, (uint8_t) 2, // Filter 12
(uint32_t) 0x00000000, (uint8_t) 2, // Filter 13
(uint32_t) 0x00000000, (uint8_t) 2, // Filter 14
(uint32_t) 0x00000000, (uint8_t) 2 // Filter 15
};
Upvotes: 0
Reputation: 61713
It looks like you missed a {
at the beginning of this line:
(uint32) 0x00000000}, {(uint8) 2} // Filter 15
Upvotes: 0