standards-compliance

Does HttpUtility.UrlEncode match the spec for 'x-www-form-urlencoded'?

人盡茶涼 提交于 2019-12-12 10:34:51
问题 Per MSDN URLEncode converts characters as follows: Spaces ( ) are converted to plus signs (+). Non-alphanumeric characters are escaped to their hexadecimal representation. Which is similar, but not exactly the same as W3C application/x-www-form-urlencoded This is the default content type. Forms submitted with this content type must be encoded as follows: Control names and values are escaped. Space characters are replaced by '+', and then reserved characters are escaped as described in RFC1738

What is the “-->” operator in C++?

笑着哭i 提交于 2019-12-12 03:37:02
问题 After reading Hidden Features and Dark Corners of C++/STL on comp.lang.c++.moderated , I was completely surprised that the following snippet compiled and worked in both Visual Studio 2008 and G++ 4.4. Here's the code: #include <stdio.h> int main() { int x = 10; while (x --> 0) // x goes to 0 { printf("%d ", x); } } I'd assume this is C, since it works in GCC as well. Where is this defined in the standard, and where has it come from? 回答1: --> is not an operator. It is in fact two separate

When does invoking a member function on a null instance result in undefined behavior?

和自甴很熟 提交于 2019-12-11 14:34:08
问题 Consider the following code: #include <iostream> struct foo { // (a): void bar() { std::cout << "gman was here" << std::endl; } // (b): void baz() { x = 5; } int x; }; int main() { foo* f = 0; f->bar(); // (a) f->baz(); // (b) } We expect (b) to crash, because there is no corresponding member x for the null pointer. In practice, (a) doesn't crash because the this pointer is never used. Because (b) dereferences the this pointer ( (*this).x = 5; ), and this is null, the program enters undefined

Printing a pointer-to-member-field

折月煮酒 提交于 2019-12-11 10:53:22
问题 I was debugging some code involving pointers to member fields, and i decided to print them out to see their values. I had a function returning a pointer to member: #include <stdio.h> struct test {int x, y, z;}; typedef int test::*ptr_to_member; ptr_to_member select(int what) { switch (what) { case 0: return &test::x; case 1: return &test::y; case 2: return &test::z; default: return NULL; } } I tried using cout : #include <iostream> int main() { std::cout << select(0) << " and " << select(3) <

How to deal with math.h pollution in Visual Studio C++?

柔情痞子 提交于 2019-12-11 09:39:08
问题 In Visual Studio 2012, I'm unable to declare certain names as global identifiers because they're already declared in math.h. Legacy issues makes it inconvenient for me to rename the identifiers in the source code. What are the options besides renaming? #include "stdafx.h" // iostream includes math.h which declares the following _CRT_NONSTDC_DEPRECATE(_y1) _CRTIMP double __cdecl y1(_In_ double _X); int y1; // error - y1 is already declared void Main() { return; } Bonus question: Is Visual

What's the status of std::vector::data()?

↘锁芯ラ 提交于 2019-12-11 03:38:55
问题 I just realized that I've been using std::vector::data() out of similarity with std::string, but a colleague pointed out that it's not standard. Apparently Gcc implements it, but looking at its include files, I found this comment: // _GLIBCXX_RESOLVE_LIB_DEFECTS // DR 464. Suggestion for new member functions in standard containers. // data access My questions are: is this method widely implemented by other compilers? is it included in C++0x? (I also wonder what DR 464 is, and also _GLIBCXX

Does the C99 standard guaranteed the binary representation of unsigned int?

本小妞迷上赌 提交于 2019-12-10 21:54:19
问题 C99 (ISO/IEC 9899:1999) 6.2.6.2/1 Integer types The values of any padding bits are unspecified. 45) A valid (non-trap) object representation of a signed integer type where the sign bit is zero is a valid object representation of the corresponding unsigned type, and shall represent the same value. For any integer type, the object representation where all the bits are zero shall be a representation of the value zero in that type. In the C99 standard, an integer type where all the bits are zero

Why would you need a “Valid XHTML & CSS” notice at the end of a page

扶醉桌前 提交于 2019-12-10 15:54:53
问题 I've seen this in the footer of various websites, most of them non-technical websites. Some websites go even further and include a W3C badge stating the fact. I don't see how this can be of any help to the targeted audience. 回答1: I can think of a few possible reasons: It may be a marketing tool. "Look, we code to appropriate standards!" This could apply to the individual who designed the site (and might include it in their portfolio), even if the company as a whole is non-technical. It could

Method Overriding and Strict Standards

跟風遠走 提交于 2019-12-10 14:28:54
问题 So I have this parent class: class GenericHTMLElement { public function addElement(GenericHTMLElement $element) {} } that is extended by these two classes class ListViewItem extends GenericHTMLElement { } class ListView extends GenericHTMLElement { /** * @param ListViewItem $element * @throws WrongTypeException */ public function addElement(GenericHTMLElement $element) { if (!$element instanceof ListViewItem) { throw new WrongTypeException("ListViewItem", $element); } parent::addElement(

std::ifstream::read or std::ofstream::write with a zero parameter?

試著忘記壹切 提交于 2019-12-10 13:29:56
问题 Is it perfectly ok (= well defined behaviour according to the standard) to call : mystream.read(buffer, 0); or mystream.write(buffer, 0); (and of course nothing will be read or written). I would like to know if I have to test if the provided size is null before calling one of these two functions. 回答1: Yes, the behavior is well-defined: both functions will go through the motions for unformatted input/output functions (constructing the sentry, setting failbit if eofbit is set, flushing the tied