Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

C static variables initialization

Status
Not open for further replies.

ghostrider123

Newbie level 3
Joined
Nov 20, 2012
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,298
Why is it compulsory to initialize static variables during compile time only?
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,598
Helped
4,784
Reputation
9,585
Reaction score
4,565
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
124,425
It isn't usually compulsory but it makes sense to.

A static variable retains it's value between calls to the function, normally a local variable is lost when the function finishes. As such, it should hold a sensible value so the first time the function is called, it already has something in it.

Brian.
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,875
Helped
14,125
Reputation
28,507
Reaction score
12,809
Trophy points
1,393
Location
Bochum, Germany
Activity points
277,851
I don't understand the exact meaning of "initialize static variables during compile time". By C specification, static variables are zeroed at application startup, an action that obviously not occurs "at compile time".

What would be the alternative? I think only disabling initialization of all or part of the static variables, which is an option with some compilers.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top