» Home » Constant » Page 1
Can constant objects with static storage duration and equal, constant initializers be coalesced?
Category : Programming Languages

Consider two objects with static storage duration and equal, constant initializers:

static const int a = 50;
static const int b = 50;

Is it valid for a compiler to combine these such that &a == &b?

(For context, I was thinking of using static constant objects to get unique addresses to use as sentinel pointer values. If i

View Replies

Combine two constant strings (or arrays) into one constant string (or array) at compile time
Category : Programming Languages

In C# and Java, it's possible to create constant strings using one or more other constant strings. I'm trying to achieve the same result in C++ (actually, in C++0x, to be specific), but have no idea what syntax I would use to achieve it, if such a thing is possible in C++. Here's an example illustrating what I want to do:

#include <stdio.h>
const char array1[] = "Hel

View Replies

Bash: Find and replace all variable characters up to a constant character with a constant string
Category : Network & Servers

I've seen many search and replace threads based on the assumption that 1. you either know what string or substring you are explicitly looking for or 2. you know the exact position it is at within the string or 3. both combined.
In my situation I have one csv file containing one column and 1M rows. e.g.


View Replies

In Ruby, is there a better way of selecting a constant (or avoiding the constant altogether) based on an incoming string of the same name?
Category : Coding

Not sure the title fully describes the problem/question I'm trying to ask, sorry.

One of my fellow developers has created classes as such:

class Widget
attr_accessor :model_type


class ModelType
MODEL1 = "model1"
MODEL2 = "model2"
MODEL3 = "model3"


View Replies

Ruby on Rails: How do I set a variable to a constant, where part of the name of the constant can change?
Category : Programming Languages

I want to do

current_user.field = User::?????????

Where ?????????? would be whatever I wanted it to be

This what I'm trying to do

Given /^"([^"]*)" is a(?:|n) "([^"]*)"$/ do |arg1, arg2|
cur_user = User.find(:first, :conditions => ['name = ?', arg1])
cur_user.update_attributes(:role => User::arg2.c

View Replies

Java switch statement: Constant expression required, but it IS constant
Category : Programming Languages

So, I am working on this class that has a few static constants:

public abstract class Foo {
public static final int BAR;
public static final int BAZ;
public static final int BAM;

Then, I would like a way to get a relevant string based on the constant:

public static String lookup(int co

View Replies

C: declare a constant pointer to an array of constant characters
Category : Programming Languages

I am trying to understand array declarations, constness, and their resulting variable types.

The following is allowed (by my compiler):

char s01[] = "abc" ; // typeof(s01) = char*
const char s02[] = "abc" ; // typeof(s02) = const char* (== char const*)
char const s03[] = "abc" ; // typeof(s03) = char const* (== const char*)


View Replies

How can I concatenate a constant and a variable and store it in a class constant with PHP?
Category : PHP
class My_class
const STATUS_ERROR = 0;
const STATUS_OK = 1;
const DB_TABLE = TABLE_PREFIX . 'class_table';

The two status consts work fine and can be accessed within class methods as self::STATUS_ERROR and self::STATUS_OK just fine.

The issue is one of how to stop the following error being thrown when I try to d

View Replies

Compare symbolic constant, enumeration, constant variable
Category : Programming Languages

symbolic constant- no type checking->the value is just substituted
enumeration- more type safe than symbolic constant
constant variables- most type safe

Anything else that can be added here?
Any difference in terms of space occupied by these?

View Replies

May a compiler optimize a reference to constant parameter to constant value?
Category : Programming Languages

Consider following function:

void func(const char & input){
//do something

Apparently it makes sense for the parameter to be constant value not
reference to constant regarding size of the char type, Now may a compiler optimize that to constant
value so that it'll be the same as following ?

void func(const char input){

View Replies

2012 / 2017 Copyrights BigHow , All Rights Reserved .