static-variables

How to preserve static variable values in JavaScript functions on postback?

Hi, I have this sample below: <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> <script type="text/javascript"> function test(){ if (test.initialized=='undefined'){ test.initialized = 'true'; } alert(test.initialized); }; </script> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID=...

Static variables in instance methods

Let's say I have this program: class Foo { public: unsigned int bar () { static unsigned int counter = 0; return counter++; } }; int main () { Foo a; Foo b; } (Of course this example makes no sense since I'd obviously declare "counter" as a private attribute, but it's just to illustrate the problem). ...

PHP: I Can only use this function once (using it in a While loop)

Hi, i got an answer on an older question wich is almost working i have a function: function vraagOp($table,$where) { static $rVraagOp; if(!$rVraagOp){ $qVraagOp = "SELECT * FROM $table WHERE $where"; $rVraagOp = mysql_query( $qVraagOp ); } return mysql_fetch_assoc( $rVraagOp ); } that i want to use li...

How to access a static variable from another file in C?

Possible Duplicate: Static variable How to access a static variable from another file in C? As a Static variable has a file scope, I think there is no way we can access it outside a file. But still I feel there might be some trick or way to do the same. ...

How am I able to access a static variable from another file?

How am I able to access a static variable from another file? Doesn't static variable have a file scope? bash-3.2$ ls a.c b.c bash-3.2$ cat a.c #include <stdio.h> static int s = 100; int fn() { /* some code */ } bash-3.2$ cat b.c #include <stdio.h> #include "a.c" extern int s; int main() { printf("s = %d \n",s); return 0; } bash-3....

Is it ok to use a static variable to initalize/register variables?

Language: C++ Toolkit: Qt4 The toolkit I'm using has a static method called int QEvent::registerEventType() to register my own event types. When I subclass this QEvent I need to supply the base class this value. QEvent::QEvent(int type). Is it ok to use a static variable to call this before application starts? Consider the following: ...

how many bytes does a static int variable need?

class a { int variable;//4 bytes } class a { static int variable;//? bytes } ...

Static variable for optimization

I'm wondering if I can use a static variable for optimization: public function Bar() { static $i = moderatelyExpensiveFunctionCall(); if ($i) { return something(); } else { return somethingElse(); } } I know that once $i is initialized, it won't be changed by by that line of code on successive calls to ...

How to create static method that evaluates local static variable once?

I have a class with static method which has a local static variable. I want that variable to be computed/evaluated once (the 1st time I call the function) and for any subsequent invocation, it is not evaluated anymore. How to do that? Here's my class: template< typename T1 = int, unsigned N1 = 1, typename T2 = int, unsigned N2 =...

Static Class Variables in Dynamic Library and Main Program

I am working on a project that has a class 'A' that contains a static stl container class. This class is included in both my main program and a .so file. The class uses the default(implicit, not declared) constructor/destructor. The main program loads the .so file using dlopen() and in its destructor, calls dlclose(). The program cra...

set static member pointer variables

I'm trying to set a static pointer variable in a class but I'm getting these errors for each variable I try to set. error C4430: missing type specifier - int assumed. Note: C++ does not support default-int error C2040: 'xscroll' : 'int' differs in levels of indirection from 'float *' error C2440: 'initializing' : cannot convert from '...

Main Program and Shared Library initializes same static variable in __static_initialization_and_destruction_0

Does anyone know why a library initialized within dlopen() would initialize a static variable owned by the main program. Both the main program and shared library have a copy of the static variable, but for some reason the shared library re-initializes the main program's copy of the static variable and destructs it, causing a segfault wh...

C++: Retrieving values of static const variables at a constructor of a static variable

I understand that the code below would result segmentation fault because at the cstr of A, B::SYMBOL was not initialized yet. But why? In reality, A is an object that serves as a map that maps the SYMBOLs of classes like B to their respective IDs. C holds this map(A) static-ly such that it can provide the mapping as a class function. ...

Making global static variables multithread safe

I have global static variables in a C library, which generate exceptions in a multithread run. I need to make them safe in some way (i.e., each thread should relate to a different instance of these variables). Any recommended methods? ...

C++ wrapper for C library

Hi, Recently I found a C library that I want to use in my C++ project. This code is configured with global variables and writes it's output to memory pointed by static pointers. When I execute my project I would like 2 instances of the C program to run: one with configuration A and one with configuration B. I can't afford to run my prog...

Constructor being called again?

I have this constructor; public UmlDiagramEntity(ReportElement reportElement, int pageIndex, Controller controller) { super(reportElement.getX1(), reportElement.getY1(), reportElement.getX2(), reportElement.getY2()); setLayout(null); this.pageIndex = pageIndex; this.controller = controller; reportElements = reportEl...

Static variables in static method in base class and inheritance

I have these C++ classes: class Base { protected: static int method() { static int x = 0; return x++; } }; class A : public Base { }; class B : public Base { }; Will the x static variable be shared among A and B, or will each one of them have it's own independent x variable (which is what I want)? ...

Static variable for communication among like-typed objects

I have a method that asynchronously downloads images. If the images are related to an array of objects (a common use-case in the app I'm building), I want to cache them. The idea is, I pass in an index number (based on the indexPath.row of the table I'm making by way through), and I stash the image in a static NSMutableArray, keyed on th...

C++: Static variable inside a constructor, are there any drawbacks or side effects?

What I want to do: run some prerequisite code whenever instance of the class is going to be used inside a program. This code will check for requiremts etc. and should be run only once. I found that this can be achieved using another object as static variable inside a constructor. Here's an example for a better picture: class Prerequisi...

Static Variables in Overloaded Functions

I have a function which does the following: When the function is called and passed a true bool value, it sets a static bool value to true When the function is called and passed a string, if the static bool value is set to true, it will do something with that string Here is my concern -- will a static variable remain the same between ...