standards

List of platforms supported by the C standard

ぃ、小莉子 提交于 2019-12-17 10:37:08
问题 Does anyone know of any platforms supported by the C standard, for which there is still active development work, but which are: not 2's complement or the integer width is not 32 bits or 64 bits or some integer types have padding bits or if you worked on a 2's complement machine, the bit pattern with sign bit 1 and all value bits zero is not a valid negative number or integer conversion from signed to unsigned (and vice versa) is not via verbatim copying of bit patterns or right shift of

Are there stackless or heapless implementation of C++?

筅森魡賤 提交于 2019-12-17 07:33:07
问题 C++ standard does not mention anything about the stack or the heap, they are implementation specific , which is true. Even though they are not part of the C++ standard, we end up using them anyway, so much that it's like they are part of the language itself and have to be taken into consideration for memory or performance purpose. Hence my question are there implementations of C++ that doesn't use stacks and heaps? 回答1: Others have already given good answers about the heap, so I'll leave that

Does new[] call default constructor in C++?

倖福魔咒の 提交于 2019-12-17 07:15:36
问题 When I use new[] to create an array of my classes: int count = 10; A *arr = new A[count]; I see that it calls a default constructor of A count times. As a result arr has count initialized objects of type A . But if I use the same thing to construct an int array: int *arr2 = new int[count]; it is not initialized. All values are something like -842150451 though default constructor of int assignes its value to 0 . Why is there so different behavior? Does a default constructor not called only for

Is it legal to use the increment operator in a C++ function call?

为君一笑 提交于 2019-12-17 07:14:49
问题 There's been some debate going on in this question about whether the following code is legal C++: std::list<item*>::iterator i = items.begin(); while (i != items.end()) { bool isActive = (*i)->update(); if (!isActive) { items.erase(i++); // *** Is this undefined behavior? *** } else { other_code_involving(*i); ++i; } } The problem here is that erase() will invalidate the iterator in question. If that happens before i++ is evaluated, then incrementing i like that is technically undefined

Hex representation of a color with alpha channel?

风流意气都作罢 提交于 2019-12-17 04:58:27
问题 Is there a W3 or any other noteworthy standard on how to represent a color (including alpha channel) in hex format? Is it #RGBA or #ARGB? 回答1: In CSS 3, to quote from the spec, "there is no hexadecimal notation for an RGBA value" (see CSS Level 3 spec). Instead you can the use rgba() functional notation with decimals or percentages, e.g. rgba(255, 0, 0, 0.5) would be 50% transparent red. RGB channels are 0-255 or 0%-100%, alpha is 0-1. In CSS 4*, you can specify the alpha channel using the

Why is `i = ++i + 1` unspecified behavior?

别说谁变了你拦得住时间么 提交于 2019-12-17 04:20:23
问题 Consider the following C++ Standard ISO/IEC 14882:2003(E) citation (section 5, paragraph 4): Except where noted, the order of evaluation of operands of individual operators and subexpressions of individual expressions, and the order in which side effects take place, is unspecified. 53) Between the previous and next sequence point a scalar object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be accessed only to

Is the order of iterating through std::map known (and guaranteed by the standard)?

依然范特西╮ 提交于 2019-12-17 03:28:31
问题 What I mean is - we know that the std::map 's elements are sorted according to the keys. So, let's say the keys are integers. If I iterate from std::map::begin() to std::map::end() using a for , does the standard guarantee that I'll iterate consequently through the elements with keys, sorted in ascending order? Example: std::map<int, int> map_; map_[1] = 2; map_[2] = 3; map_[3] = 4; for( std::map<int, int>::iterator iter = map_.begin(); iter != map_.end(); ++iter ) { std::cout << iter->second

Why will std::sort crash if the comparison function is not as operator <?

孤街浪徒 提交于 2019-12-17 02:51:38
问题 The following program is compiled with VC++ 2012. #include <algorithm> struct A { A() : a() {} bool operator <(const A& other) const { return a <= other.a; } int a; }; int main() { A coll[8]; std::sort(&coll[0], &coll[8]); // Crash!!! } If I change return a <= other.a; to return a < other.a; then the program runs as expected with no exception. Why? 回答1: std::sort requires a sorter which satisfies the strict weak ordering rule, which is explained here So, your comparer says that a < b when a =

Why will std::sort crash if the comparison function is not as operator <?

浪尽此生 提交于 2019-12-17 02:51:30
问题 The following program is compiled with VC++ 2012. #include <algorithm> struct A { A() : a() {} bool operator <(const A& other) const { return a <= other.a; } int a; }; int main() { A coll[8]; std::sort(&coll[0], &coll[8]); // Crash!!! } If I change return a <= other.a; to return a < other.a; then the program runs as expected with no exception. Why? 回答1: std::sort requires a sorter which satisfies the strict weak ordering rule, which is explained here So, your comparer says that a < b when a =

How to determine the version of the C++ standard used by the compiler?

早过忘川 提交于 2019-12-17 01:41:08
问题 How do you determine what version of the C++ standard is implemented by your compiler? As far as I know, below are the standards I've known: C++03 C++98 回答1: By my knowledge there is no overall way to do this. If you look at the headers of cross platform/multiple compiler supporting libraries you'll always find a lot of defines that use compiler specific constructs to determine such things: /*Define Microsoft Visual C++ .NET (32-bit) compiler */ #if (defined(_M_IX86) && defined(_MSC_VER) && (