literals

How Objective-C handles the memory of immutable strings [duplicate]

可紊 提交于 2019-12-11 09:38:53
问题 This question already has answers here : Do I need to release a constant NSString? (2 answers) Closed 6 years ago . In my research I've come across something peculiar. @interface Class { NSString *_string } - (void) Method1 { _string = @"ASDF"; } Intially I thought that _string was part of the autorelease pools and really didn't think about the memory aspect of it. After reading this SO post Objective C NSString* property retain count oddity I've realized that no, this is not the case, and

C++ Literals and Unicode

为君一笑 提交于 2019-12-11 05:08:47
问题 C++ Literals Environment: OS: Windows 10 Pro; Compiler: GCC latest. IDE: Code::Blocks latest. working on: Console applications. My understanding for numerical literals prefixes is that they are useful to determine the numerical value type (not sure).However, I have a lot of confusion on character and string literals prefixes and suffixes. I read a lot and spent days trying to understand the situation, but I got more questions and few answers. so I thought stack overflow could be of a lot of

What's the benefit of the trailing apostrophe in character literals

风格不统一 提交于 2019-12-11 00:59:02
问题 I am writing my own programming language and am reconsidering many aspects of my syntax right now. Something that bothers me in many most languages is the trailing apostrophe in character literals. Example With trailing slash: 'n' Without trailing slash: 'n Why do new languages (like rust f.e.) keep using a trailing apostrophe ? Seeing such languages fixing issues we had with old languages (ok, the trailing apostophe is not really an issue) leaves me thinking that there must be a benefit to

Filling multiple literals with the same value

試著忘記壹切 提交于 2019-12-10 18:57:05
问题 I have multiple literals on a page. For example, <asp:Literal id="Label1" runat="server" /> I have around 10 of these on one page and want to fill them all with the same value. Is there a good way to do that without referencing the id for each control? 回答1: Create a public property that holds the value you want to display and in the aspx use <%= propertyName %> everywhere you want to display the value. 回答2: If you're using resource files, you can set the meta:resourcekey attribute to the same

What is the best way to express a templated numeric literal?

丶灬走出姿态 提交于 2019-12-10 18:44:28
问题 I have a function that could be reduced to something like this: template<class T> T foo(T x) { return 123.45 / x; } I would like to ensure that the numeric literal 123.45 is the same type as x. Let's say that T could be any numeric type: signed/unsigned char to long-long or float to long-double. What is the most modern way to indicate that 123.45 should be of type T? My requirements No warnings should be emitted (with every warning turned on). I want the decimal number 123.45 to have the

Are arithmetic operations on literals in C# evaluated at compile time?

好久不见. 提交于 2019-12-10 13:34:02
问题 Very short question but I couldn't find a solution on the web right now. int test = 1 + 2; Will 1 + 2 be performed during run- or compile-time? Reason for asking: I think most people sometimes use a literal without specifying why it has been used or what it means because they do not want to waste a bit performance by running the calculation and I believe the calculate happens during compiletime and has no effect on performance: int nbr = 31536000; //What the heck is that? instead of int nbr =

Convert a hex string to a hex int

两盒软妹~` 提交于 2019-12-10 12:34:16
问题 I have to convert a hexadecimal string to a hexadecimal integer, like this: color = "0xFF00FF" #can be any color else, defined by functions colorto = 0xFF00FF #copy of color, but from string to integer without changes I can have RGB format too. I'm obliged to do this because this function goes after : def i2s int, len i = 1 out = "".force_encoding('binary') max = 127**(len-1) while i <= len num = int/max int -= num*max out << (num + 1) max /= 127 i += 1 end out end I saw here that hexadecimal

This is a bug in sbcl?

孤街浪徒 提交于 2019-12-10 05:32:15
问题 Why happen this in sbcl? Maybe a bug? (defclass myclass () ((s1 :initform '((a . 1) (b . 2))) (s2 :initform '((a . 1) (b . 2))))) (defparameter ins (make-instance 'myclass)) (setf (cdr (assoc 'a (slot-value ins 's1))) 43) ;; change only slot s1 ;; here my problem (slot-value ins 's1) ;; => ((a . 44) (b . 2))) (slot-value ins 's2) ;; => ((a . 44) (b . 2))) But if change :initform to : (defclass myclass () ((s1 :initform '((a . 1) (b . 2))) (s2 :initform '((a . 1) (b . 3))))) The problem

How do I type literal binary in VB.NET?

时光怂恿深爱的人放手 提交于 2019-12-10 03:34:33
问题 How do you type binary literals in VB.NET? &HFF // literal Hex -- OK &b11111111 // literal Binary -- how do I do this? 回答1: You could define it as string and then parse it: myBin = Convert.ToInt32("1010101010", 2) 回答2: As of VB.NET 15 there is now support for binary literals: Dim mask As Integer = &B00101010 You can also include underscores as digit separators to make the number more readable without changing the value: Dim mask As Integer = &B0010_1010 回答3: Expanding on codymanix's answer...

Is this legal C/C++? `int* p = (int[]) {1,2,3} ;`

元气小坏坏 提交于 2019-12-10 03:26:43
问题 This answer of mine generated some comments claiming that the following construct is not legal C/C++: void f (int* a) ; f ((int[]){1,2,3,4,0}) ; (see this ideone link for a full program). But we weren't able to resolve the issue. Can anybody shed any light on this? What do the various standards have to say? 回答1: It's valid C99 as far as I can tell - that's passing a compound literal. The C99 standard has this as an example (§6.5.2.5/9): EXAMPLE 1 The file scope definition int *p = (int []){2,