Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Structure Initializers: Are Undefined Members Zero'd?

Reply
Thread Tools

Structure Initializers: Are Undefined Members Zero'd?

 
 
Michael B Allen
Guest
Posts: n/a
 
      09-07-2006
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

 
Reply With Quote
 
 
 
 
markpapadakis
Guest
Posts: n/a
 
      09-07-2006

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"

 
Reply With Quote
 
 
 
 
Kevin D. Quitt
Guest
Posts: n/a
 
      09-07-2006
On 7 Sep 2006 11:22:44 -0700, "markpapadakis" <(E-Mail Removed)> wrote:
>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
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
class members vs instance members hdixon Python 3 07-09-2006 06:56 PM
Difference between static final members and final static members(if any)? JFCM Java 4 02-07-2006 11:32 AM
Which members are created automatically, which members are not inherited? lovecreatesbeauty C Programming 43 02-06-2006 11:36 PM
Templates: Members Vs. non-members Dave C++ 3 08-10-2004 11:23 AM
Can nested class members access private members of nesting class? CoolPint C++ 8 12-14-2003 02:30 PM



Advertisments