standards

Is it legal to use memset(,0,) on array of doubles?

孤人 提交于 2019-11-28 08:01:21
Is it legal to zero array of doubles (using memset(,0,)) or struct containing doubles ? The question implies two different things: (1) From the point of view of C standard, is this UB of not ? (on a fixed platform, how can this UB ... it just depends of floating representation that's all ...) (2) From practical point of view: is it ok on intel platform ? (no matter what standard is saying). The C99 standard Annex F says: This annex specifies C language support for the IEC 60559 floating-point standard. The IEC 60559 floating-point standard is specifically Binary floating-point arithmetic for

Scope resolution operator on enums a compiler-specific extension?

做~自己de王妃 提交于 2019-11-28 07:42:28
问题 On this question, there's an answer that states: You can use typedef to make Colour enumeration type accessible without specifying it's "full name". typedef Sample::Colour Colour; Colour c = Colour::BLUE; That sounds correct to me, but someone down-voted it and left this comment: Using the scope resolution operator :: on enums (as in "Colour::BLUE") is a compiler-specific extension, not standard C++ Is that true? I believe I've used that on both MSVC and GCC, though I'm not certain of it. 回答1

Overloading global swap for user-defined type

爱⌒轻易说出口 提交于 2019-11-28 07:40:41
The C++ standard prohibits declaring types or defining anything in namespace std , but it does allow you to specialize standard STL templates for user-defined types. Usually, when I want to specialize std::swap for my own custom templated type, I just do: namespace std { template <class T> void swap(MyType<T>& t1, MyType<T>& t2) { t1.swap(t2); } } ...and that works out fine. But I'm not entirely sure if my usual practice is standard compliant. Am I doing this correctly? What you have is not a specialization, it is overloading and exactly what the standard prohibits. (However, it will almost

Using duplicate parameters in a URL

橙三吉。 提交于 2019-11-28 07:08:03
问题 We are building an API in-house and often are passing a parameter with multiple values. They use: mysite.com?id=1&id=2&id=3 Instead of: mysite.com?id=1,2,3 I favor the second approach but I was curious if it was actually incorrect to do the first? 回答1: I'm not an HTTP guru, but from what I understand there's not a definitive standard on the query part of the URL regarding multiple values, it's typically up to the CGI that handles the request to parse the query string. RFC 1738 section 3.3

Why argument type of `putchar()`, `fputc()` and `putc()` is not `char`?

做~自己de王妃 提交于 2019-11-28 05:04:16
问题 Does anybody know Why argument type of putchar() , fputc() and putc() is not char , but argument type of putwchar() , fputwc() and putwc() is wchar_t ? See also this and this. 回答1: The answer is 'legacy' (or 'history'). Before the C90 standard, there were no function prototypes and all arguments to all functions were subject to default promotion rules, so a char was automatically passed as an int ( short was promoted to int too, and float to double , and similarly for unsigned types). The

Why doesn't the compiler detect and produce errors when attempting to modify char * string literals?

纵饮孤独 提交于 2019-11-28 04:55:05
问题 Assume the following two pieces of code: char *c = "hello world"; c[1] = 'y'; The one above doesn't work. char c[] = "hello world"; c[1] = 'y'; This one does. With regards to the first one, I understand that the string "hello world" might be stored in the read only memory section and hence can't be changed. The second one however creates a character array on the stack and hence can be modified. My question is this - why don't compilers detect the first type of error? Why isn't that part of

C++11 and the lack of polymorphic lambdas - why?

此生再无相见时 提交于 2019-11-28 04:21:00
I've been reviewing the draft version of the C++11 standard. Specifically the section on lambdas , and I am confused as to the reasoning for not introducing polymorphic lambdas. For example, amongst the 100001 ways polymorphic lambdas could be used, I had hoped we could use code such as the following: template<typename Container> void foo(Container c) { for_each(c.begin(), c.end(), [](T& t) { ++t; }); } What were the reasons: Was it that the committee ran out of time? That polymorphic lambdas are too hard to implement? Or perhaps that they are seen as not being needed by the PTB ? Note: Please

VS2010 C and C++ - enforce ANSI compliance for Linux/gcc compatibility?

元气小坏坏 提交于 2019-11-28 04:13:44
问题 I'm taking a class in which I'm required to write some C++ apps for Linux. I really, really dislike the dev tools available under Linux, but I love VS2010. Is there any sort of compiler switch which will enforce ANSI or gcc compatibility in VC++? Or can I swap the compiler out for gcc and still use the VS environment? 回答1: You can disable Microsoft extensions to the ANSI C and ANSI C++ standards by specifying the /Za flag, which will make the compiler emit errors if you use non-standard C and

When to use ellipsis after menu items

假装没事ソ 提交于 2019-11-28 03:54:21
In pretty much all applications that have a menu bar, some of the items have an ellipsis (...) after them, and some don't. Is there a well known convention on when to put that ellipsis there and when not to? When do you do it? Do you do it? I have looked at various windows applications, and this is what I have come to: Ellipsis Menu items which opens a form that require user input to do something (Replace, Go to, Font) No ellipsis Menu items which just does something (Cut, Paste, Exit, Save) Menu items which opens a form that does not require user input (About, Check for Updates) But then

Why does INVOKE facility in the C++11 standard refer to data members?

馋奶兔 提交于 2019-11-28 03:49:31
问题 $ 20.8.2 of the standard describes the INVOKE facility that is mostly used to describe how callables are called with variadic argument lists throughout the standard library: Define INVOKE (f, t1, t2, ..., tN) as follows: — (t1.*f)(t2, ..., tN) when f is a pointer to a member function of a class T and t1 is an object of type T or a reference to an object of type T or a reference to an object of a type derived from T; — ((*t1).*f)(t2, ..., tN) when f is a pointer to a member function of a class