literals

Deprecated conversion from string literal to 'char*'

橙三吉。 提交于 2019-12-17 06:35:04
问题 I have a program which declares an array of strings like this: char *colors[4] = {"red", "orange", "yellow", "blue"}; But I get the above compiler warning. It compiles but I'd rather use the non-deprecated way(if there is one). I've tried to find out what it means, but I can't seem to figure it out. I've heard using 'const' before 'char' works, but it would be helpful if someone could explain what the error means. Thanks. 回答1: The strings that you enter: "red", "organge" etc are "literal",

Setting Short Value Java

有些话、适合烂在心里 提交于 2019-12-17 06:14:25
问题 I am writing a little code in J2ME. I have a class with a method setTableId(Short tableId) . Now when I try to write setTableId(100) it gives compile time error. How can I set the short value without declaring another short variable? When setting Long value I can use setLongValue(100L) and it works. So, what does L mean here and what's the character for Short value? Thanks 回答1: In Java integer literals are of type int unless they are suffixed with letter 'L' or 'l' (Capital L is preferred as

Setting Short Value Java

馋奶兔 提交于 2019-12-17 06:14:20
问题 I am writing a little code in J2ME. I have a class with a method setTableId(Short tableId) . Now when I try to write setTableId(100) it gives compile time error. How can I set the short value without declaring another short variable? When setting Long value I can use setLongValue(100L) and it works. So, what does L mean here and what's the character for Short value? Thanks 回答1: In Java integer literals are of type int unless they are suffixed with letter 'L' or 'l' (Capital L is preferred as

How do you specify a byte literal in Java?

ε祈祈猫儿з 提交于 2019-12-17 05:40:55
问题 If I have a method void f(byte b); how can I call it with a numeric argument without casting? f(0); gives an error. 回答1: You cannot. A basic numeric constant is considered an integer (or long if followed by a "L"), so you must explicitly downcast it to a byte to pass it as a parameter. As far as I know there is no shortcut. 回答2: You have to cast, I'm afraid: f((byte)0); I believe that will perform the appropriate conversion at compile -time instead of execution time, so it's not actually

Empty set literal?

帅比萌擦擦* 提交于 2019-12-17 05:33:27
问题 [] = empty list () = empty tuple {} = empty dict Is there a similar notation for an empty set ? Or do I have to write set() ? 回答1: No, there's no literal syntax for the empty set. You have to write set() . 回答2: Just to extend the accepted answer: From version 2.7 and 3.1 python has got set literal {} in form of usage {1,2,3} , but {} itself still used for empty dict. Python 2.7 (first line is invalid in Python <2.7) >>> {1,2,3}.__class__ <type 'set'> >>> {}.__class__ <type 'dict'> Python 3.x

What does the M stand for in C# Decimal literal notation?

為{幸葍}努か 提交于 2019-12-17 03:34:15
问题 In order to work with decimal data types, I have to do this with variable initialization: decimal aValue = 50.0M; What does the M part stand for? 回答1: It means it's a decimal literal, as others have said. However, the origins are probably not those suggested elsewhere in this answer. From the C# Annotated Standard (the ECMA version, not the MS version): The decimal suffix is M/m since D/d was already taken by double . Although it has been suggested that M stands for money, Peter Golde recalls

Addresses of two char pointers to different string literals are same

﹥>﹥吖頭↗ 提交于 2019-12-17 03:34:08
问题 #include<stdio.h> #include<string.h> int main() { char * p = "abc"; char * p1 = "abc"; printf("%d %d", p, p1); } When I print the values of the two pointers, it is printing the same address. Why? 回答1: Whether two different string literals with same content is placed in the same memory location or different memory locations is implementation-dependent. You should always treat p and p1 as two different pointers (even though they have the same content) as they may or may not point to the same

Why is [] faster than list()?

大憨熊 提交于 2019-12-17 01:19:51
问题 I recently compared the processing speeds of [] and list() and was surprised to discover that [] runs more than three times faster than list() . I ran the same test with {} and dict() and the results were practically identical: [] and {} both took around 0.128sec / million cycles, while list() and dict() took roughly 0.428sec / million cycles each. Why is this? Do [] and {} (and probably () and '' , too) immediately pass back a copies of some empty stock literal while their explicitly-named

How do I do a literal *int64 in Go?

那年仲夏 提交于 2019-12-16 23:57:10
问题 I have a struct type with a *int64 field. type SomeType struct { SomeField *int64 } At some point in my code, I want to declare a literal of this (say, when I know said value should be 0, or pointing to a 0, you know what I mean) instance := SomeType{ SomeField: &0, } ...except this doesn't work ./main.go:xx: cannot use &0 (type *int) as type *int64 in field value So I try this instance := SomeType{ SomeField: &int64(0), } ...but this also doesn't work ./main.go:xx: cannot take the address of

What is the syntax for declaring a constant string[char] AA?

懵懂的女人 提交于 2019-12-14 03:46:05
问题 The following declaration: const(string[char]) AA1 = [ 'a' : "fkclopel", 'b' : "poehfftw" ]; void main(string args[]){} gives me: C:...\temp_0186F968.d(1,27): Error: non-constant expression ['a':"fkclopel", 'b':"poehfftw"] while it would work with other type kinds. 回答1: You can initialize associative array constants inside a module constructor: const /+ or immutable +/ (string [char]) AA1; static this () { AA1 = [ 'a' : "fkclopel", 'b' : "poehfftw" ]; } import std.stdio; void main () {writeln