Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

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
15,271
Helped
4,970
Reputation
9,962
Reaction score
4,801
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
129,640
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
49,399
Helped
14,438
Reputation
29,140
Reaction score
13,231
Trophy points
1,393
Location
Bochum, Germany
Activity points
284,301
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.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top