constants

Creating array with constant

I was working on a program in Netbeans on Linux using a gcc compiler when, upon switching to Visual C++ on Windows 7, the code failed to compile as Visual C++ says it expected constant expression on several lines. On Netbeans, I simply did something similar to char name[fullName.size()];, while on Visual C++, I tried, among other things,...

Counter that will remember its value

I have a task to operate on complex number. Each number consists of double r = real part, double i = imaginary part and String name. Name must be set within constructor, so I've created int counter, then I'm sending its value to setNextName function and get name letter back. Unfortunately incrementing this 'counter' value works only with...

PHP use of undefined constant error

Using a great script to grab details from imdb, I would like to thank Fabian Beiner. Just one error i have encountered with it is: Use of undefined constant sys_get_temp_dir assumed 'sys_get_temp_dir' in '/path/to/directory' on line 49 This is the complete script <?php /** * IMDB PHP Parser * * This class can be used to retrieve data...

Assigning const value to const error in php

<?php class Lala { const a = "a"; const b = a . "b"; } ?> Parse error: syntax error, unexpected '(', expecting ',' or ';' on line 4 What's the problem with it? ...

Initializing a Global Struct in C

What is the best way to accomplish the following in C? #include <stdio.h> struct A { int x; }; struct A createA(int x) { struct A a; a.x = x; return a; } struct A a = createA(42); int main(int argc, char** argv) { printf("%d\n", a.x); return 0; } When I try to compile the above code, the compiler reports th...

The Benefits of Constants

I understand one of the big deals about constants is that you don't have to go through and update code where that constant is used all over the place. Thats great, but let's say you don't explicitly declare it as a constant. What benefit(s) exist(s) to take a variable that HAPPENS to actually not be changed and make it a constant, will t...

What is the point of a constant in C#

Can anyone tell what is the point of a constant in C#? For example, what is the advantage of doing const int months = 12; as opposed to int months = 12; I get that constants can't be changed, but then why not just... not change it's value after you initialize it? ...

In Ada how do I initialise an array constant with a repeated number?

I need an array of 820 zeros for using with a mathematical function. In C I could just write the following and the compiler would fill the array: const float EMPTY_NUMBER_A[820] = { 0.0, }; However in Ada that isn't possible. I really don't want to hard code the 820 elements as 0.0. Is there a way to get the compiler to do it? typ...

Calling a method of a constant object parameter

Here is my code that fails: bool Table::win(const Card &card) { for (int i = 0; i < cards.size(); i++) if (card.getRank() == cards[i].getRank()) return true; return false; } Error message is: passing 'const Card' as 'this' argument of 'int Card::getRank()' discards qualifiers. When I get a copy of the card and change the...

Storing class constants (for use as bitmask) in a database?

Let's say I have a class called Medium which can represent different types of media. For instance: uploaded video embedded video uploaded image embedded image I represent these types with contants, like this: class MediumAbstract { const UPLOAD = 0x0001; const EMBED = 0x0010; const VIDEO = 0x0100; ...

Configurable ruby logger setup: Logger.new().level = variable

Hi, I want to change the logging level of an application (ruby). require 'logger' config = { :level => 'Logger::WARN' } log = Logger.new STDOUT log.level = Kernel.const_get config[:level] Well, the irb wasn't happy with that and threw "NameError: wrong constant name Logger::WARN" in my face. Ugh! I was insulted. I could do this ...

How to define a constant when running script/server?

I want to start up my Rails development server like this: script/server OFFLINE_MODE=1 and have a method in application_controller.rb that checks for the presence of that constant: helper_method :offline_mode? def offline_mode? defined?(OFFLINE_MODE) ? true : false end so I can hide stuff in my app when I'm coding without access ...

Get interface constant name using its value

This might not have a major usecase in projects ,but i was just trying a POC kind of project where in i get the key code,and using its value i want to print the key name on screen so i want to relive myself off writing switch cases ,so thinking of going by reflection. Is there a way to get the constant integer of interface's name using i...

PHP class constant string variable spanning over multiple lines

I want to have a string variable for a PHP class, which would be available to all methods. However, this variable is quite long, so I want to separate it into multiple lines. For example, $variable = "line 1" . "line 2" . "line 3"; But above doesn't work. I tried EOD, but EOD is not allowed within class. An...

C++ where to initialize static const

Hi, I have a class class foo { public: foo(); foo( int ); private: static const string s; }; Where is the best place to initialize the string s in the source file? ...

Does Powershell support constants?

I would like to declare some integer constants in Powershell. Is there any good way to do that? ...

Constant NSDictionary/NSArray for class methods.

I am trying to code a global lookup table of sorts. I have game data that is stored in character/string format in a plist, but which needs to be in integer/id format when it is loaded. For instance, in the level data file, a "p" means player. In the game code a player is represented as the integer 1. This let's me do some bitwise ope...

C# using consts in static classes

I was plugging away on an open source project this past weekend when I ran into a bit of code that confused me to look up the usage in the C# specification. The code in questions is as follows: internal static class SomeStaticClass { private const int CommonlyUsedValue = 42; internal static string UseCommonlyUsedValue(...) ...

GWT - problems with constants in css

Hi, I'm new to GWT; I'm building a small sample app. I have several CSS files. I'm able to successfully use the ClientBundle and CssResource to assign styles to the elements defined in my UiBinder script. Now I'd like to take it one step further and introduce CSS constants using @def css-rule. The @def works great when I define a co...

What is the use of interface constants?

I am learning Java and just found that the Interface can have fields, which are public static and final. I haven't seen any examples of these so far. What are some of the use cases of these Interface Constants and can I see some in the Java Standard Library? ...