LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-15-2012, 01:02 AM   #1
Santoshkb
Member
 
Registered: Sep 2007
Posts: 56

Rep: Reputation: 15
Question What differs static and global variable storagewise


What differs in storage of global vs static in memory layout,
please correct me.

Global variable stored in data segment.
* uninitialized seg - if uninitialized
* initialized segment - if initialized at defination itself.

Static variable in data segment
always initialized segment; (bec for unitialized it initializes to zero)

But how it cases permission restriction within source file(for static) or across process(global).

Any field in symbol table?

Thanks much in adv
-Santosh
 
Old 01-15-2012, 02:53 AM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Are you talking about C? If so, the static qualifier prevents linking to the symbol from any other compilation unit. If you don't use the static storage class, the symbol implicitly has external linkage. When using gcc, static is equivalent to __attribute__ ((visibility ("hidden"))).
Kevin Barry

Last edited by ta0kira; 01-16-2012 at 11:37 AM. Reason: fixed __attribute__
 
Old 01-15-2012, 07:40 AM   #3
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
If this is C, global and static are the same for memory layout and initialization. Either is initialized to zero if not explicitly initialized.

Traditional C implementations have a special segment for global and static variables that were not explicitly initialized. That entire segment is zeroed at load time, because that is more efficient than zeroing individual variables.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Java non-static variable cannot be referenced from a static context issue rickrvo Programming 2 02-12-2010 03:26 PM
global static const - c++ emarri Programming 5 09-07-2006 03:11 AM
Java: non-static variable this cannot be referenced from a static context chief_officer Programming 4 05-29-2006 01:37 PM
C++: difference between static method variable and static class variable? Thinking Programming 3 01-16-2006 10:08 AM
where does static and global variables stored raviksp General 0 04-28-2005 12:23 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration