Continue to Site

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?
 

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.
 
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

Back
Top