global-variables

Prevent linker from removing globals

I am using static global variables constructors as a trick to conveniently register functions, the idea goes something like this: typedef int (*FuncPtr)(int); struct RegHelper { RegHelper(const char * Name, FuncPtr Func) { Register(Name, Func); } } #define REGISTER(func) RegHelper gRegHelper_ ## func (#func, func); ...

In XSLT how do I increment a global variable from a different scope?

I am processing an XML file where I want to keep count of the number of nodes, so that I can use it as an ID as I write new nodes. At the moment I have a global variable called 'counter'. I am able to access it within a template, but I haven't found a way of manipulating it within a template. Here is a condensed version of my XSLT file...

How do I access the Properties namespace from within a console app?

Hey everyone.. I am trying to store/retrieve a value that is stored in the Application Settings. From within my console application I can not seem to access the Properties.Setting namespace. My web surfing has revealed that a little more work might be needed to do this from within a Console application. How does one do this? string tes...

Why are global variables bad, in a single threaded, non-os, embedded application

Most of the objections I see to using global variables make sense since they refer to issues of multiple threads, thread safety, etc. But in a small, single threaded, non-OS, case, what objections do you have? In my case, I'm writing my embedded system in "C", if it matters. I'm also the only developer on the product. Why would elimin...

SQL Server 2000 DTS packages suddenly not updating global variables

I've had a couple of DTS packages that run as scheduled jobs that worked fine for weeks after they were designed and deployed. They basically query a database and return data for a particular date range, outputting it in the form of text files for transmission to vendors. The first step in each process is to query a process log table t...

How to create a global variable in Squeak?

I don't mean a class variable. I want a variable that can be used everywhere. Where should I define it? [in squeak] ...

What is better: Static variable V.S. Asp.NET Application Session ?

Say you want to share some resource, like a class or a variable across all threads/sessions within a ASP.NET web application. What is better? 1) A static variable having thread-safe accessors to that static variable? 2) Or a ASP.NET application session variable? ...

How do I persist data without global variables?

I'm used to scripting languages. PHP, Javascript etc. and I've written a few relatively simple Java and C# apps. This is a question I've repeatedly needed an answer for, and I imagine I'm not the only one. Let's say I'm in Javascript. I have function A(), called by the GUI, which retrieves some value. Function B(), also called by the ...

Global.asax, global variables, and editing with code

I have two questions: 1) I have a few global variables for my website declared in my global.asax file. They are simple, small key/value pairs and there are only a few of them. Is this a good practice for values that are small and need to be accessed by almost every page on my website? Storing them in the database and requiring a db look...

How can I make a variable static (or "global") in Classic ASP?

I want to make my variable static or "global" - so the same effect as static in .NET; every session that accesses it gets the same result, and if one session modifies it it affects everyone else too. How can I achieve this in Classic ASP? ...

Problem with Global Variables

I'm somewhat new to OOP programming so it's very likely I'm making some stupid mistake. Here is my problem. When running my code I get the following error: Fatal error: Call to a member function checkLogin() on a non-object in /application/libraries/Session.php on line 30 Below is the Session.php file (I've commented line 30 to mak...

Why does assigning to my global variables not work in Python?

I'm having terrible trouble trying to understand python scoping rules. With the following script: a = 7 def printA(): print "Value of a is %d" % (a) def setA(value): a = value print "Inside setA, a is now %d" %(a) print "Before setA" printA() setA(42) print "After setA" printA() Gives the unexpected (to me) output of:...

When to use static variables?

I'm currently doing a project in C# with a lot of rendering, and throughout almost all the classes there's a constant value of the type integer being used for scaling of the rendering. I know I could define this constant in one place as a normal variable and then pass it around, but this seemes really cumbersome. When is it acceptable to...

How to declare a global variable in a .js file

Hi I need a few global variables that i need in all .js files. For eg. consider the following 4 files 1) global.js 2) js1.js 3) js2.js 4) js3.js Is there a way that i can declare 3 global variables in global.js and access them in any of the other 3 .js files considering I load all the above 4 files into a html doc Can someone pl...

IoC vs global variable in library.

So say that I have type that takes some parameters in the constructor, like this: public MyType(IComObject wrapper,string table) {} now IComObject is a wrapper over a two different COM objects. All(90%) of my types have to use IComObject, so in good DI fashion (to allow for testing) I am passing IComObject into every type that needs...

Sharing global variables across multiple servers/applications.

I am looking to set up a central point of control for settings that exist across several web servers, server applications, and possibly even internal desktop tools. The current situation is that I have a settings file on each webserver or within each application, with Global Variables defined: Admin Email, Where to store uploaded files,...

Mixing Zend and Old Procedural code

We have a really old legacy code base that uses globals like they're going out of fashion - nearly all of the inter-page communication is done via globals and sessions or both. This could be changed as a last resort but ideally I don't want to touch any of it as everything I touch could introduce more bugs :-p. Anyway, We're incorporati...

What's a good way to refactor a growing number of javascript/jquery functions?

I'm working on a project where we are doing a lot of custom javascript and especially jquery, on an mvc style project. The only problem is that I keep adding more and more global functions/variables and they are piling up. I've got a few files but I'm unsure how to split some of the stuff up into separate files. I've thought about co...

Outer Variable Access in PHP Class

Consider the following situation file: ./include/functions/table-config.php containing: . . $tablePages = 'orweb_pages'; . . file: ./include/classes/uri-resolve.php containing: class URIResolve { . . var $category; . . function process_uri() { ... $this->category = $tablePages; ... } . . } file: ./settings.php containing: . . req...

in Ruby, how to use global variables or constant values?

I have a program that looks like: $offset = Point.new(100, 200); def draw(point) pointNew = $offset + point; drawAbsolute(point) end draw(Point.new(3, 4)); the use of $offset seems a bit weird. In C, if we define something outside of any function, it is a global variable automatically. I wonder why in Ruby, it has to be $offse...