constants

How do I specify an integer literal of type unsigned char in C++?

I can specify an integer literal of type unsigned long as follows: const unsigned long example = 9UL; How do I do likewise for an unsigned char? const unsigned char example = 9U?; This is needed to avoid compiler warning: unsigned char example2 = 0; ... min(9U?, example2); I'm hoping to avoid the verbose workaround I currently h...

String Constants Vs Resource Bundle in an Java web Application

From past Year are so, we have developed an application, in which we have used the static String Constants to store the Constants. Like public static final String PAYMENT_CHEQUE = "cheque"; Where Ever I Require i.e. in the jsp pages as well the Action class I will be refering to the Above String Constant I am thinking after reviewing th...

correct idiom for std::string constants?

I have a map that represents a DB object. I want to get 'well known' values from it std::map<std::string, std::string> dbo; ... std::string val = map["foo"]; all fine but it strikes me that "foo" is being converted to a temporary string on every call. Surely it would be better to have a constant std::string (of course its probably ...

Why won't this work in PHP?

$constPrefix = '_CONST_'; if (strstr($content, $constPrefix)) { $constants = array('PHP_VERSION', '__FILE__'); foreach($constants as $constant) { $constantOutput = eval($constant); $content = str_replace($constPrefix . $constant, $constantOutput, $content); } } Basically, just trying to parse some content a...

Defining class constant in PHP

I would like to define a class constant using a concatenation of an existing constant and a string. I can't predefine it because only scalars are allowed for predefining constants, so I currently have it as part of my constructor with a defined() function checking if it is already defined. This solution works but my constant is now unnec...

Using enum as integer constant in C#

My question is pretty simple, but I didn't find a way to implement my code the way I want it to be. So I started wondering if the code I want to implement is not good. And if it is, what's the best way to do it. Here it goes: class InputManager { SortedDictionary<ushort,Keys> inputList = new SortedDictionary<ushort,Keys>(); ...

How to invoke C compiler under gcc

According to my memory the following piece of code should compile fine on C++ but not in C. Only problem is how to test it? It compiled fine with g++ and also with gcc. I'm assuming that g++ is C++ compiler and gcc is C compiler. I've tried it with mingw under Windows. Am I correct? if not then how to compile it using C compiler. int ma...

Can't get ride of "this decimal constant is unsigned only in ISO C90" warning

Hi, I'm using the FNV hash as a hashing algorithm on my Hash Table implementation but I'm getting the warning in the question title on this line: unsigned hash = 2166136261; I don't understand why this is happening because when I do this: printf("%u\n", UINT_MAX); printf("2166136261\n"); I get this: 4294967295 2166136261 Which ...

Is there a way to access datetime constants in Kohana 3?

Before I used a framework, I'd often define things like so (so my code makes more sense to read) define('MINUTE', 60); define('HOUR', MINUTE * 60); // etc Is anything like this built into Kohana 3, or should I specify this myself (perhaps in bootstrap.php)? ...

How to group Windows API constants

When defining Windows API const values, is it better to have them as const public const int SW_HIDE = 0; public const int SW_SHOWNORMAL = 1; public const int SW_NORMAL = 1; public const int SW_SHOWMINIMIZED = 2; public const int SW_SHOWMAXIMIZED = 3; public const int SW_MAXIMIZE = 3; public const int SW_SHOWNOACTIVATE = 4; public const ...

Using Macros to Define Constants for CUDA

I'm trying to reduce the number of instructions and constant memory reads for a CUDA kernel. As a result, I have realised that I can pull out the tile sizes from constant memory and turn them into macros. How do I define macros that evaluate to constants during preprocessing so that I can simply adjust three values and reduce the number...

Where Constants should be stored in the database

I've been wondering whether constants like "Approved, disapproved, pending" or "Single, married, divorced" should be grouped up in a single table holding references to what module they are used at in the database or into separate tables for each relevant module. Which one is more practical? ...

How to have abstract and overriding constants in C# ?

Hi all, My code below won't compile. What am i doing wrong? I'm basically trying to have a public constant that is overridden in the base class. public abstract class MyBaseClass { public abstract const string bank = "???"; } public class SomeBankClass : MyBaseClass { public override const string bank = "Some Bank"; } Thanks as a...

PHP, SPL predefined constants

where can i get some references about SPL predefined constants like SELF_FIRST,CHILD_FIRST ? on php.net i don't get much(just their type). ...

How can I use CodeDom to create a decimal constant?

I have this function in my generator. Private Sub AddBoundedValue(ByVal boundedValue As Object, ByVal type As CodeTypeDeclaration, ByVal numericType As Type, name As String) If boundedValue IsNot Nothing Then Dim constant As New CodeMemberField(numericType, name) constant.Attributes = MemberAttribut...

How do I declare an array as a constant in Objective-c?

The following code is giving me errors: // constants.h extern NSArray const *testArray; // constants.m NSArray const *testArray = [NSArray arrayWithObjects: @"foo", @"bar"]; The error I get is initializer element is not constant Or if I take away the pointer indicator (*) I get: statically allocated instance of Objective-C class ...

Js constants with variables inside.

I know I'm able to this in PHP, but I can't remember the name or the way to do it, so I'll just explain what it is, and when someone tells me how it's called I'll update this question. I have some error messages defined as constants on javascript, however, some of those messages need to contain dynamic part as in the following example. ...

AS3 Override const

I am trying to do the following: public class character extends entity { public const type:int = CHARACTER; } public class entity extends Sprite { public const type:int = INVALID; public const INVALID:int = -1; public const CHARACTER:int = 1; } But the compiler throws: Error: A conflict exists with inherited definition dieEngine:e...

How can I pass a constant to a Perl subroutine?

I have got as follows: use constant ABC => ('one', 'two', 'three'); and I want to pass this constant to variations_with_repetition(\@data, $k) subroutine as @data. How should I do that? ...

Single-letter prefix for PHP class constants?

I've noticed many (all?) PHP constants have a single-letter prefix, like E_NOTICE, T_STRING, etc. When defining a set of class constants that work in conjunction with one another, do you prefer to follow similar practice, or do you prefer to be more verbose? class Foo { // let's say 'I' means "input" or some other relevant word ...