473,378 Members | 1,067 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,378 software developers and data experts.

C99 struct initialization (C99/gcc)

Question about C99/gcc struct initialization:

void ffoo(void) {
struct FOO { int a,b,c; };
struct foo = { .b = 22 };

What happens now to foo.a and foo.c ? Are they initialized to 0,
or left unitialized ?

Y.L.

Feb 5 '06 #1
3 4134
ji******@yahoo.com a écrit :
Question about C99/gcc struct initialization:

void ffoo(void) {
struct FOO { int a,b,c; };
struct foo = { .b = 22 };
Handy, isn't it ?
What happens now to foo.a and foo.c ? Are they initialized to 0,
Yes.
or left unitialized ?


No.

--
A+

Emmanuel Delahaye
Feb 5 '06 #2
Thats one good thing you get with C99.

ji******@yahoo.com wrote:
Question about C99/gcc struct initialization:

void ffoo(void) {
struct FOO { int a,b,c; };
struct foo = { .b = 22 };

What happens now to foo.a and foo.c ? Are they initialized to 0,
or left unitialized ?

Y.L.


Feb 5 '06 #3
(I saved this to reply to later, in case no one else did. I saw
no useful replies, so here is one.)

In article <11*********************@g43g2000cwa.googlegroups. com>
<ji******@yahoo.com> wrote:
Question about C99/gcc struct initialization:

void ffoo(void) {
struct FOO { int a,b,c; };
struct foo = { .b = 22 };
This is a syntax error. Presumably you mean:

struct FOO foo = { .b = 22 };
What happens now to foo.a and foo.c ? Are they initialized to 0,
or left unitialized ?


In C99, unmentioned members of an otherwise-initialized aggregate
are initialized to zero. So foo.a and foo.c are set to 0.

What GNUC does with them is off-topic. :-)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Feb 20 '06 #4

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

Similar topics

2
by: Kevin P. Fleming | last post by:
I've got an enum and a structure: enum option_type { O_STRING, O_BOOL, O_NUMBER }; struct option_s { char *name;
3
by: sathyashrayan | last post by:
The standard confirms that the following initialization of a struct struct node { --- --- } struct node var = {NULL};
33
by: Chris Fogelklou | last post by:
What is wrong with the above? Don't worry, I already know (learned my lesson last week.) It is for the benefit of our resident compiler guru who seems to think you need the cast. I thought it...
10
by: pocmatos | last post by:
Hi all, Using -std=c99 to enforce the c99 standard in gcc I get: $ gcc -Wall -std=c99 timespec.c timespec.c: In function 'main': timespec.c:5: error: storage size of 'a' isn't known...
8
by: sarathy | last post by:
Hi, I read the following points in K&R "Section A8.7 Initialization". Seems like i have a problem with them. * All expressions in the initialization of constant object/array must be constant...
12
by: Yusuf | last post by:
I'm sorry for the second post in as many hours, and both about structs. The code below compiles. The variables test1 and test2 are structures of datatype teststruct1 and teststruct2. The size of...
3
by: Hallvard B Furuseth | last post by:
to find the required alignment of a struct, I've used #include <stddef.h> struct Align_helper { char dummy; struct S align; }; enum { S_alignment = offsetof(struct Align_helper, align) };
2
by: dj3vande | last post by:
Is this code, as the complete contents of a translation unit, valid C90 that initializes the struct foo to contain copies of the values passed to bar()? -------- struct foo { int i; void *v;...
160
by: DiAvOl | last post by:
Hello everyone, Please take a look at the following code: #include <stdio.h> typedef struct person { char name; int age; } Person;
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.