warning: missing braces around initializer

Last post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When I compile the following fragment I get the warnings shown below. It compiles ok with VC, so I believe it is an issue with AVR-GCC, but i could be wrong.

#define MAX_OUT 3
#define NUM_AUD_LVLS 2

static const unsigned char phys_audio_out[MAX_OUT][NUM_AUD_LVLS]=
// Source Left Right
{ 0x1F, 0x20, // 1
0x21, 0x12, // 2
0x13, 0x24 }; // 3

audio.c 6:warning: missing braces around initializer
audio.c 6:warning: (near initialization for 'phys_audio_out[0]')

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

VC is wrong. GCC is correctly pointing out a syntax error.

phys_audio_out is defined as a 2-dimensional array, or said another way, an array of arrays. When initializing this variable, the data must take on the same type structure of the variable. The data that you have is a 1-dimensional array, which is not the same type as the variable. Change the declaration to below:

#define MAX_OUT 3
#define NUM_AUD_LVLS 2

static const unsigned char phys_audio_out[MAX_OUT][NUM_AUD_LVLS]=
{
{0x1F, 0x20},
{0x21, 0x12},
{0x13, 0x24}
};

So now you have phys_audio_out declared as a 3-element array with each element being a 2-element array of constant unsigned character. The data initializer now matches the type.

Eric