Python regex – r prefix

Because \ begin escape sequences only when they are valid escape sequences. >>> ‘\n’ ‘\n’ >>> r’\n’ ‘\\n’ >>> print ‘\n’ >>> print r’\n’ \n >>> ‘\s’ ‘\\s’ >>> r’\s’ ‘\\s’ >>> print ‘\s’ \s >>> print r’\s’ \s Unless an ‘r’ or ‘R’ prefix is present, escape sequences in strings are interpreted according to … Read more

Type of integer literals not int by default?

As far as C++ is concerned: C++11, [lex.icon] ΒΆ2 The type of an integer literal is the first of the corresponding list in Table 6 in which its value can be represented. And Table 6, for literals without suffixes and decimal constants, gives: int long int long long int (interestingly, for hexadecimal or octal constants … Read more

Are string literals const?

They are of type char[N] where N is the number of characters including the terminating \0. So yes you can assign them to char*, but you still cannot write to them (the effect will be undefined). Wrt argv: It points to an array of pointers to strings. Those strings are explicitly modifiable. You can change … Read more

Java: how do I get a class literal from a generic type?

You can’t due to type erasure. Java generics are little more than syntactic sugar for Object casts. To demonstrate: List<Integer> list1 = new ArrayList<Integer>(); List<String> list2 = (List<String>)list1; list2.add(“foo”); // perfectly legal The only instance where generic type information is retained at runtime is with Field.getGenericType() if interrogating a class’s members via reflection. All of … Read more

Multicharacter literal in C and C++

It makes it easier to pick out values in a memory dump. Example: enum state { waiting, running, stopped }; vs. enum state { waiting = ‘wait’, running = ‘run.’, stopped = ‘stop’ }; a memory dump after the following statement: s = stopped; might look like: 00 00 00 02 . . . . … Read more