constants

How does PHP uses constants (defines)

Imagine I have this constant in PHP: define('APP_PATH', str_replace('//', '/', str_replace('\\', '/', dirname(__FILE__) . '/'))); When I use APP_PATH in my application, does PHP execute the code (dirname, and the two str_replace on __FILE__) each time or PHP execute the code once and store the result in APP_PATH ? I hope I'm clear eno...

dealloc all constant values used at final view controller

Hi friends, I am working in login/logout from my current application in iphone sdk. I am using many constant value in my application in various view controller. is it possible dealloc all values at final view controller? Any suggestions? Thanks in advance Regards, sathish ...

How to redefine a Ruby constant without warning?

I'm running some ruby code which evals a .rb file everytime its date changes. In the file, I happen to have constant definitions, like Tau = 2 * Pi and of course they make the interpreter display the unwanted "already initialized constant" warning every time. So, I'd like to have the following functions: def_if_not_defined(:Tau, 2 * ...

Storing property value names as String constants - performance and memory usage?

I use around 1000 properties associated with a specific java.util.Properties which is backed by a file. The main reason for the file is to change them without recompiling the program and to allow users to adjust their according to their taste. Some of the properties are used only in one place in the code, but there are some properties th...

C++ and CONST: How to use UINT32 in the typedef place of FLAG and use CONST FLAG flag; inside the structure?ong

Hello All, I am new to C++ programming. I am analyzing a code and I found the following: typedef unsigned short UINT16; typedef unsigned long UINT32; typedef UNIT16 FLAG; //within a structure, struct x { const FLAG& flag; //what this means?? }; When I change the FLAG datatype to UNIT32, then FLAG& is returning some other value...

How to judge whether a Constant has been defined within a module namespace, not a global one?

I have two Const with the same name; One is a global const, and the other is defined under the namespace Admin. But I need to distinguish them;The global one has already defined, and the scoped one need to auto defined if it has not been defined yet: A = 'A Global Const' module Admin A = 'A Const within the Admin namespace' if...

PHP - Using a constant's value to reference a data member.

Hello, I am trying to access one class object's data member by using a constant. I was wondering if this is possible with a syntax similar to what I am using? When I attempt to do this in the following script I get this error: Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM class Certificate { const BALANCE = 'cert_ba...

Search Attached Sources in Eclipse

Is there any way that Eclipse will let me search within attached sources of referenced libraries? I'm trying to find all the places where a public static final String constant is used. ...

Why can you not declare constants, in methods with Ruby?

Consider the following, StubFoo is a stub of Foo, which I wish to stub out for some tests. class Runner def run Foo = StubFoo foo = Foo.new # using Foo... end end This generates the following error message: Dynamic constant assignment Yet, in RSpec I can do the following, which works and is perfectly legal: i...

C: enum VS #define for mathematical constants?

I'm wondering what would be the best way to store math constants that are used throughout an entire program? #define PI 3.14159265 #define SPEEDOFLIGHT 2.99792458e8 or enum constants { PI = 3.14159265; SPEEDOFLIGHT = 2.99792458e8; } Thanks ...

NSString Assignment & Retaining

Just a simple question on NSStrings, I have a piece of code that assigns a value to a string, depending on what is found it is either assigned a value by substringToIndex or the constant string @"0.00", is it okay to use // Save if value found, otherwise set to 0.00 if (parsedCharacters == nil || [parsedCharacters isEqualToString:@""]) ...

"Recursive" constants in perl

Is there some conviented way to use one constant when defining another constant in perl? The following obviously does not work use constant { MAIN_DIR => "/path/to/some/dir", PROP_DIR => MAIN_DIR . "/sub_dir", PROP_FILE => PROP_DIR . "/props.props", }; The only think I could think of is multiple use constant lines, but...

expected specifier-qualifier-list before 'extern'

Hi guys, I'm trying to create a class with global constants: //Resources.h #import <Foundation/Foundation.h> @interface Resources : NSObject { extern NSString * const MY_CONST; } @end and //Resources.m #import "Resources.h" @implementation Resources NSString * const MY_CONST = @"my constant"; @end And getting this nasty error...

Union (or Concat, etc..) with Constant values and projection.

I've discovered a very nasty gotcha with Linq-to-sql, and i'm not sure what the best solution is. If you take a simple L2S Union statement, and include L2S code in one side, and constants in the other, then the constants do not get included in the SQL Union and are only projected into the output after the SQL, resulting in SQL errors ab...

[C++] Expected constant expression fails miserably in switch statement..

Say I have a class "Code" defined like this, with a user specified type conversion to int: class Code { public: int code; std::string description; Code (const int c, const std::string& d) : code(c), description(d) { ; } operator int() const { return code; } }; And a second class "Master" using the code class: cl...

c++ redefine variable as constant

I have a struct: struct s { UINT_PTR B_ID; }; s d; d.B_ID=0x1; That works fine, but I want d.B_ID to be constant. I tried to use (const) but it didn't work. So after I put a value to d.B_ID, then I want make it a constant. Any ideas? EDIT ok i don't want the whole struct a constant. when i set timer and use the b.B_ID as an i...

checking for status transition

I've created a simple function which allows me to determine which status options a change can have. For example a status of 'Pending' can only be changed to 'Active', 'Rejected' and 'Removed'. In my class I store these as constants which reference the necessary record in a status column for purposes of comparison throughout the site. M...

Visibility of object constants

I found out that object constants in PHP always have public visibility so it is not possible to set them to protected or private like this: <?php class MyClass { protected const constant = "this won't work"; } ?> What's the explanation for this? I can't think of a good reason to force constants to be public. ...

Why I'm allowed to assign a new address to a vector containing constant pointers?

Hi, I think the title is clear on explaining my problem.... consider the following snippet: class Critter { int m_Age; }; int main() { vector<Critter* const> critters; for(int i = 0; i < 10; ++i) critters.push_back(new Critter()); critters[2] = new Critter(); return 0; } Shouldn't the line critters[2] =...

What is an effective way to hold a universal constant on an iphone app?

Hey, I'm trying to create an iPhone app in which I connect to an API and get a security string and id with which to make requests to the api. The string and id change every time the app is run, and multiple view controllers in the application need the information. How can I effectively store that information so it can be easily access...