473,320 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Missing initializer

For the following code:

struct S
{
char t[5][5];
int flags;
};

void func(void)
{
struct S s = { 0 };
}

I get a "warning: missing initializer" from gcc in C99 mode.
Is there something wrong with my code or is this just
paranoia from the compiler. (My intention was that all
members of 's' be zero-initialized).

Nov 14 '05 #1
3 13876
"Old Wolf" <ol*****@inspire.net.nz> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
For the following code:

struct S
{
char t[5][5];
int flags;
};

void func(void)
{
struct S s = { 0 };
}

I get a "warning: missing initializer" from gcc in C99 mode.
Is there something wrong with my code

Not that I can see.
or is this just
paranoia from the compiler. (My intention was that all
members of 's' be zero-initialized).


The above should do just that. Perhaps the following
form will remove the warning:

struct S s = {{0}};

Or be very explicit:

struct S s = {{0}, 0};

BTW what does the gcc documentation say about this warning?

-Mike
Nov 14 '05 #2
Old Wolf wrote:
struct S
{
char t[5][5];
int flags;
};

void func(void)
{
struct S s = { 0 };
}

I get a "warning: missing initializer" from gcc in C99 mode.


Marked OT since my post is mostly about gcc. I get:

temp.c: In function `func':
temp.c:9: warning: missing braces around initializer
temp.c:9: warning: (near initialization for `s.t')
temp.c:9: warning: unused variable `s'

These warnings all make sense (implicit braces are a nasty source of
potential errors and good to warn about). I don't see yours. My
command-line is:

gcc -std=c99 -Wall temp.c -o temp

Perhaps you misread it? If not, perhaps you have an older version of gcc
with a known bug? I have 3.3.4 20040623.
--
Derrick Coetzee
I grant this newsgroup posting into the public domain. I disclaim all
express or implied warranty and all liability. I am not a professional.
Nov 14 '05 #3
Old Wolf wrote:
For the following code:

struct S
{
char t[5][5];
int flags;
};

void func(void)
{
struct S s = { 0 };
}

I get a "warning: missing initializer" from gcc in C99 mode.
Is there something wrong with my code or is this just
paranoia from the compiler. (My intention was that all
members of 's' be zero-initialized).


struct S s = {{{0}},0};

seems to do the trick. The outermost braces are for the struct,
the next set for the array of arrays, and the innermost set for
the array of char. This also shuts up the missing brace warning
that you would get with

gcc --std=c00 -W -Wall -c test.c

HTH, HAND.
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Alexander Stippler | last post by:
Hi, I wonder about the behaviour of como and icc on some very simple program. I thought initializing members of classes, which are of class type, would be 'direct initialized' (as the standard...
2
by: Todd Nathan | last post by:
Hi. have this code and compiler problem. GCC 2.95.3, BeOS, error "initializer element is not constant" #ifdef FILEIO { static struct { char *sfn; FILE *sfd; } stdfiles = {
9
by: Player | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello all. I am in the process of teaching myself C# and I think I am doing OK. I have learnt how to how to call the right constructor of a...
12
by: Pawel | last post by:
Hallo group members Could You tell hw to write this code in order not to get warning from subject: #include <iostream> using namespace std; using namespace __gnu_cxx; struct entry {
3
by: Ham Pastrami | last post by:
class Point { public: const int x, y; Point(int x, int y); } Point::Point(int x, int y) : x(x), y(y) { }
4
by: Roman Mashak | last post by:
Hello, say I've a code: .... struct device_defs { unsigned int vendor; unsigned int dev; unsigned int mask; unsigned long data; };
6
by: Marvin Barley | last post by:
I have a class that throws exceptions in new initializer, and a static array of objects of this type. When something is wrong in initialization, CGI program crashes miserably. Debugging shows...
9
by: dissectcode | last post by:
I couldn't find an anser on google...The following code is a tiny made-up example showing the problem I am looking at, at work. I have a struct: struct door_t { BOOL color; BOOL size; ...
1
by: yookoala | last post by:
Hello, I'm compiling something with GCC 4.4.1 Here I got some error from make. It says: This is the content of line 233 to 291:
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.