473,396 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,396 software developers and data experts.

static structures

Hello,

I have a question about the C language.

This piece of code is from the glibc library.

My question is about the static struct

The question is....

Are static structures automatically initialized ?

static struct random_data unsafe_state =
{
/* FPTR and RPTR are two pointers into the state info, a front and a rear
pointer. These two pointers are always rand_sep places aparts, as they
cycle through the state information. (Yes, this does mean we could get
away with just one pointer, but the code for random is more efficient
this way). The pointers are left positioned as they would be from the
call:
initstate(1, randtbl, 128);
(The position of the rear pointer, rptr, is really 0 (as explained above
in the initialization of randtbl) because the state table pointer is set
to point to randtbl[1] (as explained below).) */

.fptr = &randtbl[SEP_3 + 1],
.rptr = &randtbl[1],

/* The following things are the pointer to the state information table,
the type of the current generator, the degree of the current polynomial
being used, and the separation between the two pointers.
Note that for efficiency of random, we remember the first location of
the state information, not the zeroth. Hence it is valid to access
state[-1], which is used to store the type of the R.N.G.
Also, we remember the last location, since this is more efficient than
indexing every time to find the address of the last element to see if
the front and rear pointers have wrapped. */

.state = &randtbl[1],

.rand_type = TYPE_3,
.rand_deg = DEG_3,
.rand_sep = SEP_3,

.end_ptr = &randtbl[sizeof (randtbl) / sizeof (randtbl[0])]
};

Bye,
Skybuck.
Nov 14 '05 #1
4 2639
Skybuck Flying wrote:
Hello,

I have a question about the C language.

This piece of code is from the glibc library.

My question is about the static struct

The question is....

Are static structures automatically initialized ?


Yes, they usually are, but you won't like the values of the members,
since they contain arbitrary data when automatically initialized.

\Steve

--

Steve Graegert {C/C++ && Java && .NET}
CSI Technology Group (StReG)
<graegerts(AT)cs(DOT)technologies(DOT)de>
Nov 14 '05 #2
Skybuck Flying wrote:
Hello,

I have a question about the C language.

This piece of code is from the glibc library.

My question is about the static struct

The question is....

Are static structures automatically initialized ?


Yes they are. Depending on the type of the members, their values are
either initialized to '0' (integer for example) and null for pointer types.

\Steve

--

Steve Graegert {C/C++ && Java && .NET}
CSI Technology Group (StReG)
<graegerts(AT)cs(DOT)technologies(DOT)de>
Nov 14 '05 #3

In article <41***********************@newsread4.arcor-online.net>, Steve Graegert <st****@caths.co.uk> writes:
Skybuck Flying wrote:

Are static structures automatically initialized ?


Yes, they usually are, but you won't like the values of the members,
since they contain arbitrary data when automatically initialized.


Wrong on all counts.

Structures with static duration are always initialized. If they have
an explicit initializer, they're initialized to the values it contains;
if it does not initialize every field of the structure, those fields
are initialized as follows:

- integer types are initialized to 0
- floating types are initialized to 0.0
- pointer types are initialized to null
- union types are initialized according to the type of their first
member
- array types are initialized according to their element type, for
every element in the array
- structure types are initialized recursively, following the same
rules

Structures with static duration, and without an explicit initializer,
are initialized as if they had an initializer of {0}. That is, each
member of the structure is initialized using the rules above.

Obviously, on systems where all the default initializer values happen
to share the representation all-bits-zero, the implementation can
simply fill static structures with all-bits-zero when initializing
them (aside from non-zero explicit initializers); but regardless of
the representations of the default initializer values, that's what
the implementation must do for static structures.

See ISO 9899-1990 6.5.7.

--
Michael Wojcik mi************@microfocus.com

The lark is exclusively a Soviet bird. The lark does not like the
other countries, and lets its harmonious song be heard only over the
fields made fertile by the collective labor of the citizens of the
happy land of the Soviets. -- D. Bleiman
Nov 14 '05 #4
Michael Wojcik wrote:
In article <41***********************@newsread4.arcor-online.net>, Steve Graegert <st****@caths.co.uk> writes:
Skybuck Flying wrote:
Are static structures automatically initialized ?


Yes, they usually are, but you won't like the values of the members,
since they contain arbitrary data when automatically initialized.

Wrong on all counts.


Yes, I admitted to that by reposting a correct comment. I was simply not
considering the _static_ part of the question asked. My answer is true
for non-static structures. Must have been a bit inattentively while writing.

Steve
Nov 14 '05 #5

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

Similar topics

3
by: Steven T. Hatton | last post by:
Sorry about the big code dump. I tried to get it down to the minimum required to demonstrate the problem. Although this is all done with GNU, I believe the problem I'm having may be more general. ...
12
by: dual0 | last post by:
Hello, I found some function like void static foo(...){ .... } what does the static keyword stand for? what is a static function?
8
by: Peter B. Steiger | last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C is a simple word game that involves stringing together random lists of words. In the Pascal version the whole array was...
12
by: Joe Narissi | last post by:
I know how to create and use static constructors, but is there a such thing as a static destructor? If not, then how do you deallocate memory intialized in the static constructor? Thanks in...
2
by: Vivek Ragunathan | last post by:
Hi Are the members in a static class in C# class synchronized for multiple thread access. If yes, are all static members in a C# class auto synchronized ? Regards Vivek Ragunathan
27
by: arkmancn | last post by:
Any comments? thanks. Jim
17
by: copx | last post by:
I don't know what to think of the following.. (from the dietlibc FAQ) Q: I see lots of uninitialized variables, like "static int foo;". What gives? A: "static" global variables are initialized...
4
by: Steffen Bobek | last post by:
Extension methods are made for use with instances. I'd like to "misuse" them as static methods, too. Let me tell you my ambition: I use an extension method to serialize objects somehow like this:...
2
by: Andreas Lundgren | last post by:
Hi! I want to put some values in static memory, and then be able to reference this data from my code in a decent way by referencing AllData.Data. (All code beneth is placed outside functions.) ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.