standards

Does Standard define null pointer constant to have all bits set to zero?

浪尽此生 提交于 2019-11-27 08:37:23
问题 ( I'm quoting ISO/IEC 9899:201x ) Here we see that, integer constant expression has an integer type: 6.6 Constant expressions 6. An integer constant expression shall have integer type and shall only have operands that are integer constants, enumeration constants, character constants, sizeof expressions whose results are integer constants, _Alignof expressions, and floating constants that are the immediate operands of casts. Cast operators in an integer constant expression shall only convert

What is the rationale for exponent and mantissa sizes in IEEE floating point standards?

蹲街弑〆低调 提交于 2019-11-27 08:23:08
问题 I have a decent understanding of how floating point works, but I want to know how the specific exponent and mantissa sizes were decided upon. Are they optimal in some way? How can optimality be measured for floating point representations (I assume there are several ways)? I imagine these issues are addressed in the official standard, but I don't have access to it. 回答1: According to this interview with Will Kahan, they were based on the VAX F and G formats of the era. Of course that doesn't

Integer overflow in C: standards and compilers

你离开我真会死。 提交于 2019-11-27 08:15:28
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 of uniqueness, let's take the standard to be C99 and the compiler to be gcc. But I would be interested

Authoritative description of ObjectiveC string literals? [closed]

岁酱吖の 提交于 2019-11-27 08:06:07
问题 The Apple ObjectiveC description implies that NSStrings exist by showing examples, and that NSString literals are written as @ "<string content>" Amazingly, that's all it says, and these only show up in examples without any discussion. Is that document really the only reference document? Digging around, I found this blog which seems to have a lot of useful information. But is it right? Is there an authoritative document describing precisely what one can say (syntax) in an NSString literal,

does c++ standard prohibit the void main() prototype?

风流意气都作罢 提交于 2019-11-27 07:49:15
问题 In section 3.6.1.2 of both C++ Standard 1998 and 2003 editions, An implementation shall not predefine the main function. This function shall not be overloaded. It shall have a return type of type int, but otherwise its type is implementation-defined. I am not a native English speaker.I do not sure what does"but otherwise" means.Whether it is to prohibit the other return type,or to give the right to C++ compiler writer? So what's the answer? 回答1: The english you quote does prohibit declaring

Is the character set of a char literal guaranteed to be ASCII?

无人久伴 提交于 2019-11-27 07:45:23
问题 Coming from a discussion started here, does the standard specify values for characters? So, is '0' guaranteed to be 48? That's what ASCII would tell us, but is it guaranteed? If not, have you seen any compiler where '0' isn't 48? 回答1: No. There's no requirement for the either the source or execution character sets to use an encoding with an ASCII subset. I haven't seen any non-ASCII implementations but I know someone who knows someone who has. (It is required that '0' - '9' have contiguous

is size_t always unsigned?

会有一股神秘感。 提交于 2019-11-27 07:44:31
As title: is size_t always unsigned, i.e. for size_t x , is x always >= 0 ? Yes . It's usually defined as something like the following (on 32-bit systems): typedef unsigned int size_t; Reference: C++ Standard Section 18.1 defines size_t is in <cstddef> which is described in C Standard as <stddef.h> . C Standard Section 4.1.5 defines size_t as an unsigned integral type of the result of the sizeof operator According to the 1999 ISO C standard (C99), size_t is an unsigned integer type of at least 16 bit (see sections 7.17 and 7.18.3). The standard also recommends that size_t shouldn't have an

Are all integer values perfectly represented as doubles? [duplicate]

情到浓时终转凉″ 提交于 2019-11-27 07:44:24
This question already has an answer here: Representing integers in doubles 5 answers My question is whether all integer values are guaranteed to have a perfect double representation. Consider the following code sample that prints "Same": // Example program #include <iostream> #include <string> int main() { int a = 3; int b = 4; double d_a(a); double d_b(b); double int_sum = a + b; double d_sum = d_a + d_b; if (double(int_sum) == d_sum) { std::cout << "Same" << std::endl; } } Is this guaranteed to be true for any architecture, any compiler, any values of a and b ? Will any integer i converted

array initialization, is referencing a previous element ok?

孤者浪人 提交于 2019-11-27 07:40:27
问题 const QPointF points[] = { QPointF(r.left() - i, r.top() - i), QPointF(r.right() + i, r.top() - i), QPointF(r.right() + i, r.bottom() + i), QPointF(r.left() - i, r.bottom() + i), points[0] // is this line valid (according to the C++ standard)? }; While this compiles with the MS Visual Studio Compiler, i am not sure if this is valid code according to the C++ Standard. Quotes from the Standard would be highly appreciated. 回答1: C++03/C++11 answer No, it's not. On the right-hand side of the = ,

Are constant C expressions evaluated at compile time or at runtime?

我们两清 提交于 2019-11-27 07:14:40
If I write a #define that performs an operation using other preprocessor constants, is the final value computed each time the macro appears at runtime? Does this depend on optimizations in the compiler, or is it covered under a standard? Example: #define EXTERNAL_CLOCK_FREQUENCY 32768 #define TIMER_1_S EXTERNAL_CLOCK_FREQUENCY #define TIMER_100_MS TIMERB_1_S / 10 Will the operation 32768 / 10 occur at runtime every time I use the TIMER_100_MS macro? I would like to avoid the following: #define EXTERNAL_CLOCK_FREQUENCY 32768 #define TIMER_1_S EXTERNAL_CLOCK_FREQUENCY #define TIMER_100_MS 3276