LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-04-2011, 05:08 PM   #1
tz_uw
LQ Newbie
 
Registered: Sep 2011
Posts: 7

Rep: Reputation: Disabled
missing braces around initializer


Code:
#include <stdio.h>
typedef struct
{
	int a[2];
}twoint;
typedef struct
{
	twoint a;
	twoint b;
}foo;
Code:
/*main code with compile error: missing braces around initializer*/
int main()
{
	foo a =
	{
		{1,2},
		{3,4}
	};
}
Code:
/*FIX: no compile error*/
int main()
{
	foo a =
	{
		{{1,2}},
		{{3,4}}
	};
}
Does this fix looks correct?
Why is it necessary to put {} around the twoint struct?
 
Old 09-04-2011, 09:44 PM   #2
tbrand
Member
 
Registered: Jul 2006
Location: Toronto, Canada
Distribution: gentoo
Posts: 33

Rep: Reputation: 17
I cut and pasted you code and I get no compiler error on neither gcc 4.4.3 or gcc 4.4.4. What compiler are you running?
 
Old 09-04-2011, 09:51 PM   #3
tz_uw
LQ Newbie
 
Registered: Sep 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
I'm using gcc 4.3.4 with warning enabled.
Thanks
 
Old 09-04-2011, 10:07 PM   #4
tbrand
Member
 
Registered: Jul 2006
Location: Toronto, Canada
Distribution: gentoo
Posts: 33

Rep: Reputation: 17
I now enabled -Wmissing-braces and am getting the same warning but it makes sense:

Code:
foo a =
  {           /* initialize foo a */
    {         /* initialize twopoint a */
      {1,2}   /* initialize array int a */
    }
    {         /* initialize twopoint b */
      {3,4}   /* initialize array int a */ 
    }
  }
 
Old 09-05-2011, 01:14 AM   #5
tz_uw
LQ Newbie
 
Registered: Sep 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
Many thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: LinuxCon Europe event launches as Linux.conf.au braces for floods LXer Syndicated Linux News 0 01-12-2011 08:21 PM
[SOLVED] Shell script braces and variables Woodsman Programming 5 08-13-2010 09:39 PM
Unexpected curly braces in expect script spawn command & bash suid problem slinx Programming 1 05-02-2008 01:47 PM
GCC giving warning - braces around initializers fcdev Programming 4 09-28-2007 01:21 AM
pthreads: mutex initializer cardias Programming 1 09-03-2004 12:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration