constants

Creating public static constants in objective-c

I need to create static constants in a class that can be used by other classes that import that class. I'm assuming that enum would be the best way to go since I have seen it been used quite often through out Cocoa classes. ...

Can I use rspec mocks to stub out version constants?

I've got code that only needs to run on a certain version of ActiveRecord (a workaround for a bug on old AR libraries). This code tests the values of ActiveRecord::VERSION constants to see if it needs to be run. Is there a way to mock out those constants in rspec so I can test that code path without relying on having the right ActiveRec...

Constant Pointer / structs

In my programming class, we have struct Time { int hours, min, sec; } We are to create a method to compute the difference between two times: Time *timeDiff(const Time *t1, const Time *t2) I thought I could create the time difference by getting everything in seconds, and then subtracting the two values, but it seems like extra wo...

What is the difference between char s[] and char *s in C?

In C, I can do like this: char s[]="hello"; or char *s ="hello"; so i wonder what is the difference? I want to know what actually happen in memory allocation during compile time and run time. ...

Constants or a register class?

I've come across a Registry Class and I'm wondering whether to bother with this or just go constants, or are there separate uses for site-wide global variables such as database connection information, website URI, etc? Here's the class I came across: <?php Class Registry { private $vars = array(); public function __se...

In C#, what's the best way to store a group of constants that my program uses?

I have various constants that my program uses. Some are strings, some are ints, and some are doubles. What's the best way to store them? I don't think I want an Enum, because the data is not all the same type, and I want to manually set each value. Should I just store them all in an empty class, or is there a better way? ...

Constants in MATLAB

I've come into ownership of a bunch of Matlab code and have noticed a bunch of "magic numbers" scattered about the code. Typically, I like to make those constants in languages like C, Ruby, PHP, etc. When googling this problem, I found that the "official" way of having constants is to define functions that return the constant value. S...

Haskell minimum/maximum Double Constant

Is there any way in Haskell to get the constant that is the largest and smallest possible positive rational number greater than zero that can be represented by doubles? ...

PHP Variable Scope

Is there a way to declare a variable so it is available in all functions. Basically I want to call: Global $varName; automatically for every function. And no, I can't use a constant. I don't think its possible but wanted to ask anyway. Thanks! :D ...

using switch statements with constants or enumerations? (Which is better)? C#

HI, I've got a simple question, but one that has been bugging me for a while. Question: When using switch statements in C#, is it considered better practice to use enums over constants or vice versa? Or is it a matter of preference? I ask this because many people seem to like using enums, but when you are switching on an int value, you...

If you can't change a variable's value in Haskell, how do you create data structures?

As per the title. I have the following code which creates a binary search tree, but if I want it created and changed dynamically with user input, how would I do that if I can't change the value of a variable in haskell?!? find :: (Ord a) => Node a -> a -> Bool find (Node val left right) s | s == val = True | s < val = find le...

PHP Zend Framework - Zend_Config and global state

I'm in the process of evaluating the benefits of Zend_Config_Ini versus using a simple constant file. e.g. - define('DB_HOST',localhost); //versus $config = new Zend_Config_Ini('/path/to/config.ini', 'staging'); echo $config->database->params->host; // prints "dev.example.com" The only thing is that the $config is not globally ac...

How to define constants in Visual C# like #define in C?

In C you can define constants like this #define NUMBER 9 so that wherever NUMBER appears in the program it is replaced with 9. But Visual C# doesn't do this. How is it done? ...

Memorable 32-bit value as a constant

I am looking for a memorable 32-bit value to be used as a constant. If possible, it should be somewhat funny too. So far, I have come up with these two: 0xcafebabe 0xdeaddad Can you please suggest some other too? Thank you. ...

Using & (addressof) with const variables in C

Text books say that & (addressof) operator doesn't apply to cannot be applied to expressions, constants, or register variables. Does constants mean only literals like 'A', '7' etc or variables declared with const keyword as well? I think this mean only literals since following code compiles:- int main() { const int i=10; const int *ip; ...

Constant string arrays

Is it possible to have a (fixed) array which stores its elements in the read-only segment of the executable and not on the stack? I came up with this code but unfortunately it is very unflexible when it comes to adding, moving or deleting items. How do I verify that the strings are indeed stored in the read-only segment? I tried readelf ...

PHP set current directory to class constant

I have a config file at the root directory of my project which contains a class of constants that are environment specific. The problem I'm having is how to set the current directory as the ROOT var. Something to the effect of: Class Config { const ROOT = dirname(__FILE__); } This isn't possible as it is a constant expression. I've ...

c#:How to use enum for storing string constants?

Possible Duplicate: Enum with strings is is possible to have string constants in enum like enum{name1="hmmm" name2="bdidwe"} if it is not so what is best way to do so? I tried it its not working for string so right now i am grouping all related constnats in one class like class operation { publi...

Static String constants VS enum in Java 5+

I've read that question & answers: http://stackoverflow.com/questions/66066/what-is-the-best-way-to-implement-constants-in-java And came up with a decision that enum is better way to implement a set of constants. Also, I've read an example on Sun web site how to add the behaviour to enum (see the link in the previously mentioned post). ...

How do I examine defined constants in PHP?

I'm stepping through the source code of CodeIgniter with Xdebug in NetBeans and I'm looking for a way to see defined constants as they are defined. If it's not possible, are there any other ways to display all defined constants? ...