literals

Should I use _T or _TEXT on C++ string literals?

一笑奈何 提交于 2019-11-30 05:50:45
For example: // This will become either SomeMethodA or SomeMethodW, // depending on whether _UNICODE is defined. SomeMethod( _T( "My String Literal" ) ); // Becomes either AnotherMethodA or AnotherMethodW. AnotherMethod( _TEXT( "My Text" ) ); I've seen both. _T seems to be for brevity and _TEXT for clarity. Is this merely a subjective programmer preference or is it more technical than that? For instance, if I use one over the other, will my code not compile against a particular system or some older version of a header file? A simple grep of the SDK shows us that the answer is that it doesn't

Is the u8 string literal necessary in C++11

孤街醉人 提交于 2019-11-30 04:55:18
From Wikipedia : For the purpose of enhancing support for Unicode in C++ compilers, the definition of the type char has been modified to be at least the size necessary to store an eight-bit coding of UTF-8. I'm wondering what exactly this means for writing portable applications. Is there any difference between writing this const char[] str = "Test String"; or this? const char[] str = u8"Test String"; Is there be any reason not to use the latter for every string literal in your code? What happens when there are non-ASCII-Characters inside the TestString? The encoding of "Test String" is the

PHP object literal

半腔热情 提交于 2019-11-30 01:10:27
In PHP, I can specify array literals quite easily: array( array("name" => "John", "hobby" => "hiking"), array("name" => "Jane", "hobby" => "dancing"), ... ) But what if I want array of objects? How can I specify object literal in PHP? I.e. in javascript it would be: [ {name: "John", hobby: "hiking"}, {name: "Jane", hobby: "dancing"} ] As BoltClock mentioned there is no object literal in PHP however you can do this by simply type casting the arrays to objects: $testArray = array( (object)array("name" => "John", "hobby" => "hiking"), (object)array("name" => "Jane", "hobby" => "dancing") ); echo

Is there a floating point literal suffix in C++ to make a number double precision?

孤街浪徒 提交于 2019-11-30 00:50:35
问题 I'm currently working on a C++ project which does numerical calculations. The vast, vast majority of the code uses single precision floating point values and works perfectly fine with that. Because of this I use compiler flags to make basic floating point literals single precision instead of the double precision, which is the default. I find that this makes expressions easier to read and I don't have to worry about forgetting a 'f' somewhere. However, every now and then I need the extra

Why does Python 3 allow “00” as a literal for 0 but not allow “01” as a literal for 1?

。_饼干妹妹 提交于 2019-11-29 23:25:41
Why does Python 3 allow "00" as a literal for 0 but not allow "01" as a literal for 1? Is there a good reason? This inconsistency baffles me. (And we're talking about Python 3, which purposely broke backward compatibility in order to achieve goals like consistency.) For example: >>> from datetime import time >>> time(16, 00) datetime.time(16, 0) >>> time(16, 01) File "<stdin>", line 1 time(16, 01) ^ SyntaxError: invalid token >>> Per https://docs.python.org/3/reference/lexical_analysis.html#integer-literals : Integer literals are described by the following lexical definitions: integer ::=

Purpose of Scala's Symbol? [duplicate]

柔情痞子 提交于 2019-11-29 20:23:45
Possible Duplicate: What are some example use cases for symbol literals in Scala? What's the purpose of Symbol and why does it deserve some special literal syntax e. g. 'FooSymbol ? Calum Symbols are used where you have a closed set of identifiers that you want to be able to compare quickly. When you have two String instances they are not guaranteed to be interned[1], so to compare them you must often check their contents by comparing lengths and even checking character-by-character whether they are the same. With Symbol instances, comparisons are a simple eq check (i.e. == in Java), so they

Type error when testing a function with a negative number

末鹿安然 提交于 2019-11-29 16:07:04
I am following along with the Learn you a Haskell for great good , I have implemented take' : take' :: (Ord i, Num i) => i -> [a] -> [a] take' n _ | n <= 0 = [] take' _ [] = [] take' n (x:xs) = x: take' (n-1) xs When testing the function with: take' -2 [2] instead of getting an empty list, I have this message: Non type-variable argument in the constraint: Num (i -> [a] -> [a]) (Use FlexibleContexts to permit this) When checking that ‘it’ has the inferred type it :: forall i a t. (Num i, Num t, Num (i -> [a] -> [a]), Num ([t] -> i -> [a] -> [a]), Ord i) => i -> [a] -> [a] I have added a space

Function literal in PHP class

有些话、适合烂在心里 提交于 2019-11-29 15:34:10
Take a look at this code, please: $array = array( 'action' => function () { echo "this works"; } ); class Test { public $array = array( "action" => function () { echo "this doesn't"; } ); } The first function literal parses fine, but the second - the one inside the class - triggers a syntax error: Parse error: syntax error, unexpected 'function' (T_FUNCTION)... Can somebody explain this to me? Is this a bug? EDIT: This is the latest PHP: 5.6.6 From the class it's a property ! Rule from properties : Declaration may include an initialization, but this initialization must be a constant value -

What are Constants and Literal constants?

无人久伴 提交于 2019-11-29 14:42:09
问题 I'm learning Python and i am just confused with the Constants and Literal constants.What are they?For what kind of purpose do we use them ? What is their difference from the normal variable? Thank you very much. Edit : I'm a true beginner.As beginner as i can say i know nothing about the programming world.Like i don't know what an expression is and vice versa. I have been learning the python language using the " A byte of python " book and somewhere in the book i came across a section which

Strange Haskell expression with type Num ([Char] -> t) => t

拟墨画扇 提交于 2019-11-29 13:24:28
While doing some exercises in GHCi I typed and got the following> ghci> (1 "one") <interactive>:187:1: No instance for (Num ([Char] -> a0)) arising from a use of ‘it’ In a stmt of an interactive GHCi command: print it which is an error, howeve if I ask GHCi for the type of the expression it does not give any error: ghci> :type (1 "one") (1 "one") :: Num ([Char] -> t) => t What is the meaning of (1 "one") ? Why does this expression gives an error, but GHCi tells it is well typed? What is the meaning of Num ([Char] -> t) => t ? Thanks. Haskell Report to the rescue! (Quoting section 6.4.1 ) An