warning: missing braces around initializer

Go To Last Post
5 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
 

Last Edited: Sat. Mar 18, 2017 - 04:38 PM
  • 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

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

Had the same issue, solved using your solution @eric. Thanks a lot :)

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

Opening up a 15 year old grave is just plain stupid.

 

Locked.

Ross McKenzie ValuSoft Melbourne Australia

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

It may be unusual to open up such an old thread, but it certainly is not "stupid" as the post is only thanking someone for providing a solution to their problem.

Its also commendable that the peraon took the time to search for an answer rather than simply start a thread.

Unusual yes, stupid....certainly not.

Just my two pence
Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

Topic locked