literals

Assign a string literal to a char* [duplicate]

半腔热情 提交于 2019-11-29 13:14:46
Possible Duplicate: How to get rid of deprecated conversion from string constant to ‘char*’ warnings in GCC? This assignment: char *pc1 = "test string"; gives me this warning: warning: deprecated conversion from string constant to 'char*' while this one seems to be fine: char *pc2 = (char*)("test string"); Is this one a really better way to proceed? Notes: for other reasons I cannot use a const char* . A string literal is a const char[] in C++, and may be stored in read-only memory so your program will crash if you try to modify it. Pointing a non-const pointer at it is a bad idea. That

Difference between N'String' vs U'String' literals in Oracle

扶醉桌前 提交于 2019-11-29 11:49:23
问题 What is the meaning and difference between these queries? SELECT U'String' FROM dual; and SELECT N'String' FROM dual; 回答1: In this answer i will try to provide informations from official resources (1) The N'' text Literal N'' is used to convert a string to NCHAR or NVARCHAR2 datatype According to this Oracle documentation Oracle - Literals The syntax of text literals is as follows: where N or n specifies the literal using the national character set ( NCHAR or NVARCHAR2 data). Also in this

Specific Collection type returned by Convenience Factory Method in Java 9

泪湿孤枕 提交于 2019-11-29 11:31:51
In Java 9 we have convenience factory methods to create and instantiate immutable List, Set and Map. However, it is unclear about the specific type of the returned object. For ex: List list = List.of("item1", "item2", "item3"); In this case which type of list is actually returned? Is it an ArrayList or a LinkedList or some other type of List? The API documentation just mentions this line, without explicitly mentioning that its a LinkedList: The order of elements in the list is the same as the order of the provided arguments, or of the elements in the provided array. The class returned by List

Assigning an integer literal to a double variable in Java

百般思念 提交于 2019-11-29 10:56:13
If I do the following double d = 0; since 0 is an integer literal, which uses 32 bits, and d is a double variable that uses 64 bits, will the remaining 32 bits be filled with random garbage, or does Java promote the literal correctly? Java promotes it correctly, otherwise there'd be a rather large body of code that was problematic :-) Section 5.1.2 of the Java language spec details this: The following 19 specific conversions on primitive types are called the widening primitive conversions: byte to short, int, long, float, or double short to int, long, float, or double char to int, long, float,

Java binary literals - Value -128 for byte

流过昼夜 提交于 2019-11-29 10:28:42
Since SE 7 Java allows to specify values as binary literal. The documentation tells me 'byte' is a type that can hold 8 Bit of information, the values -128 to 127. Now i dont know why but i cannot define 8 bits but only 7 if i try to assign a binary literal to a byte in Java as follows: byte b = 0b000_0000; //solves to the value 0 byte b1 = 0b000_0001; //solves to the value 1 byte b3 = 0b000_0010; //solves to the value 2 byte b4 = 0b000_0011; //solves to the value 3 And so on till we get to the last few possibilitys using those 7 bits: byte b5 = 0b011_1111; //solves to the value 63 byte b6 =

Literal @YES not working in iOS 5 / Xcode 4.4

元气小坏坏 提交于 2019-11-29 10:02:00
New Xcode 4.4 is out and it should support literals like @42 @"String" @23.0L @{ @"key" : obj } and @[obj1, obj2] and it should also support @YES and @NO , which isn't working when targeting latest iOS 5 (and prior). After compiling it show the error message: Unexpected type name 'BOOL': expected expression I know you can fix it by typing @(YES) and @(NO) . But I want to know the reason why it isn't working as expected. The reason is Apple forgot the parentheses here: #define YES (BOOL)1 This will be fixed in iOS 6 SDK: #define YES ((BOOL)1) In the meantime you must type @(YES) . James Webster

MySQL unicode literals

杀马特。学长 韩版系。学妹 提交于 2019-11-29 08:04:41
问题 I want to insert a record into MySQL that has a non-ASCII Unicode character, but I'm on a terminal that doesn't let me easily type non-ASCII characters. How do I escape a Unicode literal in MySQL's SQL syntax? 回答1: See: http://bugs.mysql.com/bug.php?id=10199 (Bug #10199: "Allow Unicode escape sequence for string literals.") This request has been "Open" since 2005. More details in Worklog Task #3529: Unicode Escape Sequences. From https://web.archive.org/web/20091117221116/http://eng.kaching

VBScript implicit conversion in IF statement different from variable to literals?

痞子三分冷 提交于 2019-11-29 07:53:21
We are currently having an issue due to implicit conversion in an IF statement in VBScript (Classic ASP) that don't do implicit conversion the same way when dealing with a variable or a literal. Can someone explain this behavior to me, why do VBScript acts this way ? Here is a sample of what I mean : Const c_test = 3 Dim iId : iId = 3 Dim iTestStr : iTestStr = "3" If iId = iTestStr Then Response.Write("Long variable = String variable : Equal") Else Response.Write("Long variable = String variable : Not Equal") End If Response.Write("<br/>") If c_test = iTestStr Then Response.Write("Long

NSNumber Literals

橙三吉。 提交于 2019-11-29 07:48:34
I am very new to Objective-C. I know C and C++ but Objective-C has quite the learning curve. Anyway, is there a shorter way (possibly by some kind of NSNumber literal if such exists) to write the following: [Tyler setArms:[[[NSNumber alloc] autorelease] initWithInt:1]]; Yes, just use one of the many helper functions such as numberWithInt: : [Tyler setArms:[NSNumber numberWithInt:1]]; The expression [NSNumber numberWithInt:1] is equivalent to [[[NSNumber alloc] initWithInt:1] autorelease] , which is equivalent to [[[NSNumber alloc] autorelease] initWithInt:1] . The latter expression is

Properly match a Java string literal [duplicate]

拈花ヽ惹草 提交于 2019-11-29 06:47:07
This question already has an answer here: Regex to replace all string literals in a Java file 4 answers I am looking for a Regular expression to match string literals in Java source code. Is it possible? private String Foo = "A potato"; private String Bar = "A \"car\""; My intent is to replace all strings within another string with something else. Using: String A = "I went to the store to buy a \"coke\""; String B = A.replaceAll(REGEX,"Pepsi"); Something like this. Ok. So what you want is to search, within a String, for a sequence of characters starting and ending with double-quotes? String