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

Structure Initializers: Are Undefined Members Zero'd?

Are undefined structure members in initializers set to 0?

Consider the following code:

typedef struct fns {
int (*fn1)(int n);
int (*fn2)(int n);
int (*fn3)(int n);
int (*fn4)(int n);
int (*fn5)(int n);
} fns;
static int
my_fn1(int n)
{
....
}
static int
my_fn3(int n)
{
....
}
const fns my_fns = {
my_fn1,
NULL,
my_fn3
};

Are my_fns.fn4 and my_fns.fn5 guaranteed to be NULL here?

Mike

Sep 7 '06 #1
2 2291

Michael B Allen wrote:
Are undefined structure members in initializers set to 0?

Consider the following code:

typedef struct fns {
int (*fn1)(int n);
int (*fn2)(int n);
int (*fn3)(int n);
int (*fn4)(int n);
int (*fn5)(int n);
} fns;
static int
my_fn1(int n)
{
...
}
static int
my_fn3(int n)
{
...
}
const fns my_fns = {
my_fn1,
NULL,
my_fn3
};

Are my_fns.fn4 and my_fns.fn5 guaranteed to be NULL here?

Mike
According to:
http://c-faq.com/decl/initval.html
"When an automatic array or structure has a partial initializer, the
remainder is initialized to 0, just as for statics"

Sep 7 '06 #2
On 7 Sep 2006 11:22:44 -0700, "markpapadakis" <ma***********@gmail.comwrote:
>Michael B Allen wrote:
>Are undefined structure members in initializers set to 0?
Uninitialized and static, yes. Automatic and partially initialized, yes.
>Are my_fns.fn4 and my_fns.fn5 guaranteed to be NULL here?
>According to:
http://c-faq.com/decl/initval.html
"When an automatic array or structure has a partial initializer, the
remainder is initialized to 0, just as for statics"
More importantly, they're initialized *as if* the programmer had entered a zero constant -
so yes, pointers thus initialized are guaranteed to be NULL.
--
#include <standard.disclaimer>
_
Kevin D Quitt USA 91387-4454 96.37% of all statistics are made up
Sep 7 '06 #3

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

Similar topics

19
by: Thomas Matthews | last post by:
Hi, Given a structure of pointers: struct Example_Struct { unsigned char * ptr_buffer; unsigned int * ptr_numbers; }; And a function that will accept the structure:
2
by: B. Wood | last post by:
I have written a simple program the has a structure with two members. There are two strange things going on. 1. When on of the structure members is tested in a condition, the value of the...
5
by: jimjim | last post by:
Hello, Any help will be much appreciatted. My problem is as follows: I declare as global variables: typedef struct _Node{ ..; ..;}Node; Node *Graph; in a function called initiallise(), I...
4
by: csudha | last post by:
Hi All, Can you give me the example code which explains difference between Structures and Union. As a newbie please do the needful. Thanks, csudha.
2
by: Dave Veeneman | last post by:
Is is legal to declare abstract members in non-abstract classes? How about non-abstract members in abstract classes? I am writing a base class with three derived classes. The base class will...
4
by: marco_segurini | last post by:
Hi, From my VB program I call a C++ function that gets a structure pointer like parameter. The structure has a field that contains the structure length and other fields. My problem is that...
5
by: Bill Pursell | last post by:
Suppose I have a structure with many members, and I pass a pointer to that structure to a function. I'd like the prototype of the function to specify that it will only be changing certain members...
9
by: bunty | last post by:
Hi all, I am working on 16 bit app on windows. My problem is I am using windows RECT structure. on 16 bit windows it 's all member are declared as short which allows max 32767 max value. and...
4
by: sam_cit | last post by:
Hi Everyone, I have a structure typedefed as typedef strcut { #if(MACRO == TRUE) int a; int b; #endif
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:
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
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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.