473,382 Members | 1,512 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,382 software developers and data experts.

global static vs global??

Hi,

So I came across some source code... "static int slices = 16;" which
is outside of any class or function. I know what statics are used for
inside classes/functions, but what does it mean if it's global?
Perhaps my C++ is getting a bit rusty...

Oct 16 '07 #1
2 16026
On Oct 15, 5:20 pm, Mark <mnbaya...@gmail.comwrote:
Hi,

So I came across some source code... "static int slices = 16;" which
is outside of any class or function. I know what statics are used for
inside classes/functions, but what does it mean if it's global?
Perhaps my C++ is getting a bit rusty...
nvm... my girlfriend found the answer (out of all people!). I guess
my googling skills are getting a bit rusty too:

A static global variable is never visible outside of its file, even
in the presence of ``extern'' declarations. global variable is a
variable that is accessible in every scope

Oct 16 '07 #2
"Mark" <mn*******@gmail.comwrote in message
news:11**********************@v29g2000prd.googlegr oups.com...
On Oct 15, 5:20 pm, Mark <mnbaya...@gmail.comwrote:
>Hi,

So I came across some source code... "static int slices = 16;" which
is outside of any class or function. I know what statics are used for
inside classes/functions, but what does it mean if it's global?
Perhaps my C++ is getting a bit rusty...

nvm... my girlfriend found the answer (out of all people!). I guess
my googling skills are getting a bit rusty too:

A static global variable is never visible outside of its file, even
in the presence of ``extern'' declarations. global variable is a
variable that is accessible in every scope
Yes, just to give you a little more information, it's not necessary that
"file" but that "translation unit". So a file that is included could still
see the same instance of the variable because its the same "translation
unit". A translation unit is a group of files that gets compiled to an
object file. Normally, but not always, this is one .cpp with whatever
header files it includes. At the end of compiling the translation units
(which are now object files) get linked together to form an executable.
Oct 16 '07 #3

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

Similar topics

2
by: Gianguz | last post by:
I'd like to discuss about the opportunity to have a global objects creator that introduces into a general framework (suited for multithreading) a controlled semantic to manage globals variables...
2
by: Thomas Matthews | last post by:
Hi, I'm getting linking errors when I declare a variable in the global scope, but not inside a function. The declarations are the same (only the names have been changed...). class Book {...
10
by: David P. Donahue | last post by:
When I wrote websites in VB .NET, I would often put functions in Global for all the pages to call. Now, in C#, doing so results in "references to non-static objects" and whatnot. I realize what...
8
by: Marty | last post by:
Hi, I'm new to C#, I used to code in VB.NET. Where is the best place to declare all my constants and global objects in my C# project to have them accessible globally? I have an event logger...
8
by: Vishwanathan Raman | last post by:
Hi I have a declared a static DataSet object SOBJ in Global.asax.I also have a localy defined DataSet LSOBJ in Global.asax which I am storing in Application State.Is there any technical...
8
by: Thomas Coleman | last post by:
Ok, I've obviously discovered that Global.aspx has been completely changed in ..NET 2.0. However, I haven't figured out how to declare a constant that's available to any page in my application...
37
by: eoindeb | last post by:
Sorry to ask another global variable question, but from reading other posts I'm still not sure whether to use them or not. I have a program with a set function that calls 4 other functions in...
9
by: CDMAPoster | last post by:
About a year ago there was a thread about the use of global variables in A97: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157 Best Practices by Kang...
10
by: ma | last post by:
Hello, I want to create a global class. To do this I did the followings: 1- Create a class name test. It has a public variable named mystring. public class test { public string mystring =...
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...

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.