constants

What Are Integer Literal Type? And How They Are Stored?

拥有回忆 提交于 2019-12-18 09:22:11
问题 I have just started learning C and a question has bugged me for a while now. If I write int i = -1; unsigned int j = 2; unsigned int k = -2; What is the type of integer literal -1 and 2 and -2 , and how does it get converted to get stored in signed int and unsigned int ? What is meant by signed integer, is that the property of variable or integer literal too? Like -2 is signed integer and 2 is unsigned integer? 回答1: First off, -1 is not an integer constant. It's an expression consisting of a

concatenation of string constants in java [duplicate]

我的梦境 提交于 2019-12-18 09:07:06
问题 This question already has answers here : Java String literals concatenation (2 answers) Closed 4 years ago . In C++, the best canonical way to create a multiline string of which I am aware is to create adjacent strings and let the compiler concatenate them at compile time, like this: string s = "This is a very long string ...\n" " and it keeps on going..."; In Java, the only way I know to do this is with concatenation: String s = "This is a very long string ...\n" + " and it keeps on going...

concatenation of string constants in java [duplicate]

余生颓废 提交于 2019-12-18 09:07:02
问题 This question already has answers here : Java String literals concatenation (2 answers) Closed 4 years ago . In C++, the best canonical way to create a multiline string of which I am aware is to create adjacent strings and let the compiler concatenate them at compile time, like this: string s = "This is a very long string ...\n" " and it keeps on going..."; In Java, the only way I know to do this is with concatenation: String s = "This is a very long string ...\n" + " and it keeps on going...

Is `if(CONSTANT) { … }` optimized in C/C++? [duplicate]

孤者浪人 提交于 2019-12-18 09:06:22
问题 This question already has answers here : Constants and compiler optimization in C++ (12 answers) Closed 5 years ago . Do modern compilers optimize a piece of code like if(CONSTANT) { ... } , where CONSTANT is a literal, template argument, const variable or constexpr variable? Do they remove the whole if(0) { ... } expression or "throw out" the if(1) part in if(1) { ... } ? 回答1: This is not guaranteed but most compilers of good quality will do it. C99 Rationale says in 6.4.9: if (0) { /* code

Declaring an array inside a class, and setting its size with the constructor

牧云@^-^@ 提交于 2019-12-18 05:54:51
问题 I haven't worked with c++ in a while, but I just started a project with it. This may not be possible, but Im trying to create a template class with an array that sets its size to the value of a constant which i'm trying to set with the constructor. This is the code of the constructor: Tarray(int s): start_size(s){ } This is the code that sets the array size: const int start_size; T this_array[start_size]; This is the entire file: #ifndef TARRAY_H_ #define TARRAY_H_ template<typename T> class

Having a “constants”-class in JSF

↘锁芯ラ 提交于 2019-12-18 05:51:56
问题 I'm building a web-application using JSF/Primefaces. I need to have a "constants"-class, i.e. a class that will consist of constants. These constants are mainly navigational commands that will be used throughout the application. The reason I am doing this is to avoid having instantiated Strings on an ad-hoc basis. How do I achieve this, making the constants accessible from both backing beans and XHTML files? I have tried using @ApplicationScoped and using the Singleton-pattern (Singleton

Regarding Java String Constant Pool

孤街浪徒 提交于 2019-12-18 05:47:11
问题 This is regarding the Java String Constant Pool. In one of my Programs i am decrypting the password for the database and storing it in a String. I heard that the Java Strings will be stored in a Constant pool and they won't be destroyed the VM restarts or the ClassLoader that loaded the String Quits. If it is the case my passwords will be stored in the String pool. I am Very concerned about this issue. Is there any other way to destroy these literals or anything else i can do. Please suggest

How to initialize static pointer with malloc in C?

血红的双手。 提交于 2019-12-18 04:47:10
问题 I'm trying to initiate a static variable (inside a function) with malloc in C, but I'm getting the "initializer not constant error". I know that I can't initiate a static with non constants in C, but can anyone think of a solution? I need the code to have the same effect as this: static int *p = (int *)malloc(sizeof(int)); Is there a trick/workaround? EDIT: I have a function that is called every time a flag goes high. In this function, I'm creating and starting a new thread. I declare a

Javadoc displaying value on an inner class constant using @value

青春壹個敷衍的年華 提交于 2019-12-18 03:49:21
问题 I have an inner class which declares a constant and want to display its value in Javadoc of the enclosing top-level class using the @value annotation. For example: /** * {@value #FOO_CONS} // this displays well * {@value #BAR_CONS} // this does not work (checked in the latest Eclipse) * {@value Bar#BAR_CONS} // this does not work, either */ public Foo { public static final int FOO_CONS = 1; static class Bar { public static final int BAR_CONS = 42; } } Any ideas how to display the value of BAR

What is the best way to define a global constant in PHP which is available in all files?

假装没事ソ 提交于 2019-12-18 02:00:48
问题 What is the best way to define a constant that is global, i.e., available in all PHP files? UPDATE: What are the differences between constants and class constants? Can they be used interchangeably? 回答1: Define your constant in your top .php file, that will be included in all the other scripts. It may be your front controller, your config file, or a file created for this single purpose. !defined('MY_CONST') && define('MY_CONST', 'hello'); 回答2: do the following: define("CONSTANT_NAME","value");