standards

Is the result of a cast an rvalue?

六眼飞鱼酱① 提交于 2019-11-26 17:47:57
问题 Let int a = 0; Then is (int)a an rvalue in standard C++? Different compilers show different results for this code: #include <iostream> using namespace std; void f(int& x) { cout << "l value" << endl; } void f(int&& x) { cout << "r value" << endl; } int main() { int a = 0; f((int)a); } compilers with different results: 1) http://cpp.sh/2r6 2) http://webcompiler.cloudapp.net/ 回答1: The should be an rvalue but webcompiler is running Visual Studio and Visual Studio has an extension which allows

Pascal casing or Camel Casing for C# code?

百般思念 提交于 2019-11-26 17:46:21
问题 I've been arguing with my coworkers about Pascal casing (upper camel case) vs. lower CamelCasing. They are used to lower camel casing for everything from table names in SQL databases to property naming in C# code but I like Pascal casing better, lower camel casing for variables and Pascal casing for properties: string firstName; public string FirstName { ... } But they are used to this: string _firstname; public string firstName { ... } I try to keep up with their "standard" so the code looks

Integer overflow in C: standards and compilers

☆樱花仙子☆ 提交于 2019-11-26 17:45:26
问题 Edited to include proper standard reference thanks to Carl Norum. The C standard states If an exceptional condition occurs during the evaluation of an expression (that is, if the result is not mathematically defined or not in the range of representable values for its type), the behavior is undefined. Are there compiler switches that guarantee certain behaviors on integer overflow? I'd like to avoid nasal demons. In particular, I'd like to force the compiler to wrap on overflow. For the sake

What could C/C++ “lose” if they defined a standard ABI?

℡╲_俬逩灬. 提交于 2019-11-26 17:41:24
问题 The title says everything. I am talking about C/C++ specifically, because both consider this as "implementation issue". I think, defining a standard interface can ease building a module system on top of it, and many other good things. What could C/C++ "lose" if they defined a standard ABI? 回答1: The freedom to implement things in the most natural way on each processor. I imagine that c in particular has conforming implementations on more different architectures than any other language. Abiding

Computing length of a C string at compile time. Is this really a constexpr?

浪尽此生 提交于 2019-11-26 17:27:26
I'm trying to compute the length of a string literal at compile time. To do so I'm using following code: #include <cstdio> int constexpr length(const char* str) { return *str ? 1 + length(str + 1) : 0; } int main() { printf("%d %d", length("abcd"), length("abcdefgh")); } Everything works as expected, the program prints 4 and 8. The assembly code generated by clang shows that the results are computed at compile time: 0x100000f5e: leaq 0x35(%rip), %rdi ; "%d %d" 0x100000f65: movl $0x4, %esi 0x100000f6a: movl $0x8, %edx 0x100000f6f: xorl %eax, %eax 0x100000f71: callq 0x100000f7a ; symbol stub for

Which standard specifies the AT&W AT command?

本秂侑毒 提交于 2019-11-26 17:24:43
问题 While discussing how to process AT commands with a colleague, we discovered that contrary to our belief the command AT&W (store user profile) is not specified in V.250 (it only specifies ATZ and AT&F , which are related), leaving us wondering - where is it specified then? Update: Yes, we expected the command to have its origin in the Hayes command set, virtually all the basic syntax commands does. However, most of the Hayes command have been imported into formal standards like V.250 by ITU or

Is it legal to write to std::string?

て烟熏妆下的殇ゞ 提交于 2019-11-26 17:11:45
问题 In std::string there are only const members to fetch the data like c_str(). However I can get a reference to the first element of the string via operator[] and I can write to it. For example, if I have function: void toupper(char *first,char *last_plus_one); I can write directly to vector getting a pointer to the first element: vector<char> message // has "Some Message"; toupper(&message[0],&message[0]+message.size()); Can I do same thing with std::string? string message="Some Message";

What is currently the best way to get a favicon to display in all browsers that support Favicons?

六月ゝ 毕业季﹏ 提交于 2019-11-26 17:02:15
What is currently the best way to get a favicon to display in all browsers that currently support it? Please include: Which image formats are supported by which browsers. Which lines are needed in what places for the various browsers. Brian Matthews I go for a belt and braces approach here. I create a 32x32 icon in both the .ico and .png formats called favicon.ico and favicon.png . The icon name doesn't really matter unless you are dealing with older browsers. Place favicon.ico at your site root to support the older browsers (optional and only relevant for older browsers. Place favicon.png in

Do pointers to string literals remain valid after a function returns?

亡梦爱人 提交于 2019-11-26 16:42:50
问题 Is the pointer returned by the following function valid? const char * bool2str( bool flg ) { return flg ? "Yes" : "No"; } It works well in Visual C++ and g++. What does C++ standard say about this? 回答1: On storage duration: 2.13.4 Ordinary string literals and UTF-8 string literals are also referred to as narrow string literals. A narrow string literal has type “array of n const char”, where n is the size of the string as defined below, and has static storage duration read in conjunction with

Why are std::vector::data and std::string::data different?

南笙酒味 提交于 2019-11-26 16:39:38
问题 Vector's new method data() provides a const and non-const version. However string's data() method only provides a const version. I think they changed the wording about std::string so that the chars are now required to be contiguous (like std::vector ). Was std::string::data just missed? Or is the a good reason to only allow const access to a string's underlying characters? note: std::vector::data has another nice feature, it's not undefined behavior to call data() on an empty vector. Whereas