global-variables

Global constants in Objective-C

最后都变了- 提交于 2019-12-19 02:05:17
问题 I've a file called Constants.h : extern NSString * const BASE_URL; and Constants.m : #ifdef DEBUG NSString * const BASE_URL = @"http://www.example.org "; #else NSString * const BASE_URL = @"http://localhost"; #endif First question: How can I switch DEBUG to be True and False ? I've a view controller file MyViewController.m : #import "MyViewController.h" #import "Constants.h" // this doesn't works. see above for the error. static NSString * const ANOTHER_URL = [NSString stringWithFormat:@"%@%@

NameError: global name 'HTTPError' is not defined

匆匆过客 提交于 2019-12-18 18:58:23
问题 I have a command in a try clause which I know throws an exception. I'm trying to catch it in an "except" clause, but the except clause seems to not recognize the existence of the exception. The exception, when unhandled (i.e. not enclosed in a try clause), looks like this in the interactive window: Traceback (most recent call last): File "<console>", line 1, in <module> File "C:\Users\Andy\software\Turkeys\actions.py", line 234, in annotate annotation=annotator.ncbo_annotate(thing) File "C:

“extern” inside a function?

[亡魂溺海] 提交于 2019-12-18 14:24:49
问题 Well, reading "a bit old" book ("The C programming language", second edition, by Dennis Ritchie), I came a cross the following: An external variable must be defined, exactly once, outside of any function; this sets aside storage for it. The variable must also be declared in each function that wants to access it and I was like - what?! "The variable must also be declared in each function that wants to access it". Then, I was shocked one more time: int max; /* ... */ int main() { extern int max

What object are Javascript global variables stored in?

…衆ロ難τιáo~ 提交于 2019-12-18 14:23:20
问题 Are global variables stored in specific object? For instance: var test="stuff"; console.log(window.test); console.log(document.test); console.log(this.test); All three of these tests result in undefined , so is there an object that holds these variables? I feel as though this is something stupid that I should already know, but I can't even seem to find the answer online. 回答1: I think you'll find on most browsers, they are stored in window . Far-fetched psychic debugging attempt: did you test

How can I save global application variables in WPF?

眉间皱痕 提交于 2019-12-18 13:16:32
问题 In WPF, where can I save a value when in one UserControl, then later in another UserControl access that value again, something like session state in web programming, e.g.: UserControl1.xaml.cs: Customer customer = new Customer(12334); ApplicationState.SetValue("currentCustomer", customer); //PSEUDO-CODE UserControl2.xaml.cs: Customer customer = ApplicationState.GetValue("currentCustomer") as Customer; //PSEUDO-CODE ANSWER: Thanks, Bob, here is the code that I got to work, based on yours:

Should ALL global variables be volatile-qualified?

自古美人都是妖i 提交于 2019-12-18 13:14:18
问题 In this example, does correctness require global_value to be declared volatile ? int global_value = 0; void foo () { ++ global_value; } void bar () { some_function (++global_value); foo (); some_function (++global_value); } My understanding is that volatile is "intended" for pointers to mapped memory and variables which can be modified by signals (and emphatically not for thread-safety) but it's easy to imagine that bar might compile to something like this: push EAX mov EAX, global_value inc

Should I use a global variable and if not, what instead? (Javascript)

巧了我就是萌 提交于 2019-12-18 12:47:39
问题 I'm working with several functions which need to pass a variable back and forth. Should I use a global variable or another method instead? I would also appreciate an example or two on how to implement it. Thanks, Elliot Bonneville Psuedocode of my functions: function GetXML() {//this would be a function which reads in an XML file. //Preferably it would also generate or set an object to hold the XML data. } function UseXMLData() { //I would use the XML data here. } function

Global variable in laravel controller

孤者浪人 提交于 2019-12-18 12:27:46
问题 I want the $year variable to be available in all functions of my PagesController . I tried this code but I didn't succeed. class PagesController extends Controller { public function __construct() { $dt = Carbon::parse(); $year = $dt->year; } public function index() { return view('pages.index'); } public function about() { return view('pages.about', compact('year')); } public function create() { return view('pages.create', compact('year')); } } 回答1: 1. Option: Use the AppServiceProvider In

Javascript: Global variables shared between .js files

跟風遠走 提交于 2019-12-18 11:48:52
问题 I'm having problems with global variables. Considering that I have the following files: init.html, main.html, init.js, main.js and help.js : Where, init.html: <HTML> <HEAD> <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.3.min.js"></script> <script type="text/javascript" charset="UTF-8" src="init.js" ></script> <script type="text/javascript" charset="UTF-8" src="main.js" ></script> <script type="text/javascript" charset="UTF-8" src="help.js" ></script> </HEAD> <BODY>

How to create a global variable in android? [duplicate]

落花浮王杯 提交于 2019-12-18 10:44:54
问题 This question already has answers here : Android global variable (14 answers) Closed 5 years ago . In my android application I need a place for putting the variable member id . The problem is , it is getting from the online API and I need to find a way to store / retrieve it I have tried to put it in a custom class , but the problem is , it will lose if I kill the activity, I have also know that there is a way to extends the application. So I would like to know what is the best way to store