constants

constants class in php

Hello, I once heard it's good to have one class with all your application constants so that you have only one location with all your constants. I Tried to do it this way: class constants{ define("EH_MAILER",1); } and class constants{ const EH_MAILER =1; } But both ways it doesn't work. Any suggestions? ...

Is there a way to define symbolic constants in Javascript ?

I searched if JavaScript offers a mean to define symbolic constants, but didn't find anything. Did I miss something ? Is it a common practices to use const var instead ? var const MAXIMUM_VALUE = 100; Thanx. ...

C/C++: Optimization of pointers to string constants

Have a look at this code: #include <iostream> using namespace std; int main() { const char* str0 = "Watchmen"; const char* str1 = "Watchmen"; char* str2 = "Watchmen"; char* str3 = "Watchmen"; cerr << static_cast<void*>( const_cast<char*>( str0 ) ) << endl; cerr << static_cast<void*>( const_cast<char*>( str1 ) )...

C++ binary constant/literal

I'm using a well known template to allow binary constants template< unsigned long long N > struct binary { enum { value = (N % 10) + 2 * binary< N / 10 > :: value } ; }; template<> struct binary< 0 > { enum { value = 0 } ; }; So you can do something like binary<101011011>::value. Unfortunately this has a limit of 20 digits for a ...

Where can I find a list of windows API constants

Every time I interact with dll's like the user32.dll I need constants like MF_REMOVE. Is there a overview for all that constants or a c# library that constants all these constants? ...

Best approach to define a constant (used in a constant expression) in the class?

I am trying to define a constant BUFFER_LENGTH for my class for a given usecase. //1. Using preprocessor declaration //#define BUFFER_LENGTH 12 //2.Global constant //const int BUFFER_LENGTH = 12; class MyRequest { public: //3. Define an in-class constant //static const int BUFFER_LENGTH = 12; //4. Declare an enum constan...

Rails : uninitialized constant error on Active Record destroy

Hello I am having an issue when trying to destroy an active record instance. It involves the following AR class Client < ActiveRecord::Base has_many :phone_numbers, :dependent => :destroy has_many :email_addresses, :dependent => :destroy has_many :user_clients , :dependent => :destroy has_many :users, :through => :user...

JavaScript: Inheritance and Constant declaration

Help, I have this class var jMath = { pi2: Math.PI, foo: function() { return this.pi2; } } I want to make the pi2 constant and i want jMath to inherit from Math object. How do I do that? ...

What is the purpose of Decimal.One, Decimal.Zero, Decimal.MinusOne in C#

Simple question - why does the Decimal type define these constants? Why bother? I'm looking for a reason why this is defined by the language, not possible uses or effects on the compiler. Why put this in there in the first place? The compiler can just as easily in-line 0m as it could Decimal.Zero, so I'm not buying it as a compiler shor...

Using constant variables in Objective-C expressions? Newb.

In Java static final int VCount = 21, TCount = 28, NCount = VCount * TCount; in Objective-C static int VCount = 21, TCount = 28, NCount = ???; How can I express the NCount int because it refers to variables? ...

Is it possible to declare a const of an array in BOTH Delphi and FreePascal without having the elements be constants?

A long time ago I remember I could do this in Turbo Pascal 7. Maybe I'm wrong and it's something I need to clarify, but is it possible to declare an array of strings as a constant? If not what's the option/workaround. What I have now is: type TStates = (sOne, sTwo, sThree); var TArrayOfString: array [sOne..sThree] of string = ...

Error on defining an array even though its set via a Constant...

Hi, I know this is really basic, but its got me stumped... In Objective-C I'm trying to write: const int BUF_SIZE = 3; static char buffer[BUF_SIZE+1]; But I get a storage size of buffer isn't constant. How do I make Xcode realise that I'm setting it to a constant, + 1...? Or is this not possible...? Thanks...! Joel ...

C#: Static readonly vs const

I've read around about const and static readonly fields. We have some classes which contains only constant values. Used for various things around in our system. So I am wondering if my observation is correct: Should these kind of constant values always be static readonly for everything that is public? And only use const for internal/pro...

Sharing constants across a WCF service

I have certain strings which contain special characters so they can not be shared as enum members across a WCF service. (Actually, they are keys for configuration values.) I want to be able to pass in the keys at client side and get back the config values. If there is a change, I only want to change the config keys at one place. Consta...

How can I best initialize constants from a database or servlet context?

We have constants declared in an interface in our application like this. public interface IConstants { public static final String FEVER="6"; public static final String HEADACHE="8"; } We now want to populate these constants values (6 and 8) from the database (or application servlet context). The database values stored in a lo...

Overriding constants in derived classes in C#

In C# can a constant be overridden in a derived class? I have a group of classes that are all the same bar some constant values, so I'd like to create a base class that defines all the methods and then just set the relevant constants in the derived classes. Is this possible? I'd rather not just pass in these values to each object's cons...

How can I define a variable as CONSTANT when retrieved from Web.Config?

I keep a lot of settings in AppSettings, and I was wondering if it's considered good practice to name them in UpperCase. Essentially, they're the same as Constants right? As I understand it, if you change the Web.Config, the app does a recompile. So, I was thinking, should you keep the settings in AppSettings in UPPERCASE (Assuming you...

Why doesn't Java have constants for well-known system property names?

The java.lang.System class defines a number of well-known properties. For example, you can obtain the JVM's temporary directory by looking up the "java.io.tmpdir" property: ... = System.getProperty("java.io.tmpdir"); What I don't understand is why these properties aren't defined as constants (e.g. in the java.lang.System class). This...

Should I store Enum ID/values in the db or a C# enumeration?

Say my database tables have columns like UserType, SalesType, etc. Should I have database tables with UserTypeID, userTypeName or should I just create a C# enumeration? ...

Is there a way to use const variables in the definitions of other constants?

I would like to use some previously defined constants in the definition of a new constant, but my C compiler doesn't like it: const int a = 1; const int b = 2; const int c = a; // error: initializer element is not constant const int sum = (a + b); // error: initializer element is not constant Is there a way to define a constan...