global-variables

C# : So if a static class is bad practice for storing global state info, what's a good alternative that offers the same convenience?

拟墨画扇 提交于 2019-12-18 10:34:13
问题 I've been noticing static classes getting a lot of bad rep on SO in regards to being used to store global information. (And global variables being scorned upon in general) I'd just like to know what a good alternative is for my example below... I'm developing a WPF app, and many views of the data retrieved from my db are filtered based on the ID of the current logged in user. Similarly, certain points in my app should only be accessable to users who are deemed as 'admins'. I'm currently

How to avoid “multiple definition” error for global constants?

自古美人都是妖i 提交于 2019-12-18 09:38:56
问题 I'm writing a C program using the Windows API. Each major function has its own file, and there is one header for the prototypes and includes and whatnot: // Headers & global constants #pragma once #define _WIN32_LEAN_AND_MEAN #include <Windows.h> #include <WindowsX.h> #include <Windef.h> #define szClassName TEXT("EthicsPresentationWnd") // Prototypes LRESULT CALLBACK WindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); BOOL CALLBACK FontProc1(HWND hWnd, LPARAM lParam); int APIENTRY

unused volatile variable

依然范特西╮ 提交于 2019-12-18 09:11:23
问题 If i declare a variable as volatile and if I dont use it any where in the program, will the compiler optimize that variable ? What in case of local and global declarations of volatile variables in this case? tq. 回答1: The compiler can, and probably will, eliminate (ignore) the unused volatile variable declaration (but the compiler cannot eliminate an unused global variable definition - it has to assume that some other translation unit (TU) will reference it). If the variable is local to the

Global Variable in Python

為{幸葍}努か 提交于 2019-12-18 09:09:41
问题 I am very new to Python. Not learnt classes yet. Using Python 3.2.2. Tried implement some procedural C logic. My code is spread over 2 files as follows. this file is called date.py dd,mm,yy=0,0,0 def isValidDate(d,m,y): if(d>=1 and d<=31 and m>=1 and m<=12): dd,mm,yy=d,m,y #problem print(dd,mm,yy) #problem print(d,m,y) #problem return True else: return False def printDate(): print(dd,mm,yy) #problem this file is called module1.py import date def main(): dd,mm,yy = 23,1,1984 valid = date

$_GET is empty when the url has variables

╄→гoц情女王★ 提交于 2019-12-18 08:47:19
问题 I have a url that look like this reg.php?lang=no_NO&passkey=test and im trying to get the passkey variable, but it keeps showing up blank. When I try print_r($_GET); it prints Array ( ) ?! How can this happen? The site look something like this <?php print_r($_GET); include('..\libs\Smarty.class.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv=

Assign C++ instance method to a global-function-pointer?

喜欢而已 提交于 2019-12-18 06:58:24
问题 Greetings, My project structure is as follows: \- base (C static library) callbacks.h callbacks.c paint_node.c . . * libBase.a \-app (C++ application) main.cpp In C library 'base' , I have declared global-function-pointer as: in singleheader file callbacks.h #ifndef CALLBACKS_H_ #define CALLBACKS_H_ extern void (*putPixelCallBack)(); extern void (*putImageCallBack)(); #endif /* CALLBACKS_H_ */ in single C file they are initialized as callbacks.c #include "callbacks.h" void (*putPixelCallBack)

How to hide a global variable, which is visible across multiple files?

橙三吉。 提交于 2019-12-18 05:57:34
问题 I am writing a C (shared) library. It started out as a single translation unit, in which I could define a couple of static global variables, to be hidden from external modules. Now that the library has grown, I want to break the module into a couple of smaller source files. The problem is that now I have two options for the mentioned globals: Have private copies at each source file and somehow sync their values via function calls - this will get very ugly very fast. Remove the static

Make all variables global, PHP

断了今生、忘了曾经 提交于 2019-12-18 05:50:12
问题 Is there a way to make all variables global? 回答1: To import all global variables incl. superglobals and clashing names of parameters into the functions scope: extract($GLOBALS, EXTR_REFS | EXTR_SKIP); The problem is with the superglobals here. You might want to exclude them, here is a list (PHP 5.2): /** * PHP Superglobals */ array ( 1 => 'GLOBALS', 2 => '_ENV', 3 => 'HTTP_ENV_VARS', 4 => '_POST', 5 => 'HTTP_POST_VARS', 6 => '_GET', 7 => 'HTTP_GET_VARS', 8 => '_COOKIE', 9 => 'HTTP_COOKIE_VARS

Create a global static variable in SQL Server?

只愿长相守 提交于 2019-12-18 05:49:06
问题 Is there a way to create a global variable in SQL Server, in such a way that it persists even if the server is restarted, so I can use it in functions? Example from what I need: DECLARE @@DefaultValue bit This variable should never be deleted unless I explicityl do so. 回答1: I guess this will work the best for me: CREATE FUNCTION [dbo].[fn_GetDefaultPercent]() RETURNS decimal(5,4) AS BEGIN RETURN 1.0000 END 回答2: You can have a look at something like this "Global variables" in SQL Server 回答3:

Globals variables and Python multiprocessing [duplicate]

淺唱寂寞╮ 提交于 2019-12-18 05:37:28
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Python multiprocessing global variable updates not returned to parent I am using a computer with many cores and for performance benefits I should really use more than one. However, I'm confused why these bits of code don't do what I expect: from multiprocessing import Process var = range(5) def test_func(i): global var var[i] += 1 if __name__ == '__main__': jobs = [] for i in xrange(5): p = Process(target=test