standards

Is it legal to write to std::string?

纵饮孤独 提交于 2019-11-27 15:30:25
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"; toupper(&message[0],&message[0]+message.size()); Does the standard guarantee that the location of the memory

double negation in C : is it guaranteed to return 0/1?

南笙酒味 提交于 2019-11-27 15:26:11
Is !!(x) guaranteed by the standard to return 0/1? Note that I am not asking about c++, where a bool type is defined. Mat Yes, in C99, see §6.5.3.3/4: The result of the logical negation operator ! is 0 if the value of its operand compares unequal to 0, 1 if the value of its operand compares equal to 0. The result has type int . The expression !E is equivalent to (0==E). So !x and !!y can only yield 0 or 1, as int s. For other operators, in C99, see also Is the "true" result of >, <, !, &&, || or == defined? Tim This is a comment really, but it's too long. (Please don't down vote it on that

Is using an union in place of a cast well defined?

泄露秘密 提交于 2019-11-27 15:04:14
I had a discussion this morning with a colleague regarding the correctness of a "coding trick" to detect endianness. The trick was: bool is_big_endian() { union { int i; char c[sizeof(int)]; } foo; foo.i = 1; return (foo.c[0] == 1); } To me, it seems that this usage of an union is incorrect because setting one member of the union and reading another is not well-defined. But I have to admit that this is just a feeling and I lack actual proofs to strengthen my point. Is this trick correct ? Who is right here ? Your code is not portable. It might work on some compilers or it might not. You are

Is it time to start developing with HTML5? [closed]

为君一笑 提交于 2019-11-27 14:45:28
问题 From searching SO, this question was already asked, almost a year ago now. So now with the new FF, Opera, IE, is it finally time to start developing sites with HTML5 or is it still a little premature and will cause compatibility issues? Is using HTML5 just going to require us to use more and more JS on websites to 'trick' older browsers into working properly? 回答1: If you add nice features to your site, it is possible it will be talked about and reach the news sites for some free publicity.

Why isn't there a regular expression standard?

南楼画角 提交于 2019-11-27 14:33:53
问题 I know there is the perl regex that is sort of a minor de facto standard, but why hasn't anyone come up with a universal set of standard symbols, syntax and behaviors? 回答1: There is a standard by IEEE associated with the POSIX effort. The real question is "why doesn't everyone follow it" ? The answer is probably that it is not quite as complex as PCRE with respect to greedy matching and what not. 回答2: Actually, there is a regular expression standard (POSIX), but it's crappy. So people extend

Is it legal/well-defined C++ to call a non-static method that doesn't access members through a null pointer?

霸气de小男生 提交于 2019-11-27 14:30:29
I came across the following code recently: class Foo { public: void bar(); // .. other stuff }; void Foo::bar() { if(!this) { // .. do some stuff without accessing any data members return; } // .. do normal actions using data members } The code compiles because in C++ methods are just functions that are implicitly passed a pointer for 'this' and 'this' can be checked to be NULL just like any other pointer. Obviously this code is confusing and bad practice even though it doesn't crash; it would be pretty confusing to step through the code in the debugger, see a NULL pointer is about to have a

Denormalized Numbers - IEEE 754 Floating Point

末鹿安然 提交于 2019-11-27 14:23:17
So I'm trying to learn more about Denormalized numbers as defined in the IEEE 754 standard for Floating Point numbers. I've already read several articles thanks to Google search results, and I've gone through several StackOverFlow posts. However I still have some questions unanswered. First off, just to review my understanding of what a Denormalized float is: Numbers which have fewer bits of precision, and are smaller (in magnitude) than normalized numbers Essentially, a denormalized float has the ability to represent the SMALLEST (in magnitude) number that is possible to be represented with

JSON standard - floating point numbers

女生的网名这么多〃 提交于 2019-11-27 14:18:42
问题 I am wondering whether the following floating point notation is a valid JSON notation: "result":{"base_fee":1e-005} or should the exponent notation be replaced with a decimal notation? 回答1: It is valid according to the format available at json.org as numbers can optionally have a base 10 exponent denoted by an E, uppercase or lowercase, an optional plus or minus, and one or more digits. 回答2: It's perfectly valid, according to RFC 4627 RFC 7159*: The representation of numbers is similar to

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

左心房为你撑大大i 提交于 2019-11-27 14:17:15
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 &vec.front() is undefined behavior if it's empty. In C++98/03 there was good reason to not have a non

Standard C library in mingW

我只是一个虾纸丫 提交于 2019-11-27 14:07:30
I have installed mingW to use gcc, platform windows 7. I am trying to locate the standard C library libc.a in mingW folder. no luck.. is it stored in some other name? MinGW does not build against glibc, it builds against msvcrt. As such, it uses libmsvcrtXX.a instead. 来源: https://stackoverflow.com/questions/6394512/standard-c-library-in-mingw