language-lawyer

FP: invalid operation: contradiction between C (UB) and IEEE 754 (WDB)?

北城以北 提交于 2021-01-07 01:06:06
问题 N2479 C17..C2x working draft — February 5, 2020 ISO/IEC 9899:202x (E): 6.3.1.4 Real floating and integer: 1 When a finite value of standard floating type is converted to an integer type other than _Bool, the fractional part is discarded (i.e., the value is truncated toward zero). If the value of the integral part cannot be represented by the integer type, the behavior is undefined . IEEE 754-2019: 5.8 Details of conversions from floating-point to integer formats: When a NaN or infinite

Three questions: Is NULL - NULL defined? Is (uintptr_t)NULL - (uintptr_t)NULL defined? [duplicate]

↘锁芯ラ 提交于 2021-01-05 06:00:46
问题 This question already has answers here : Is the behavior of subtracting two NULL pointers defined? (4 answers) Closed last month . 1.Is NULL - NULL defined.? Is (char *)NULL - (char *)NULL defined.? Is (uintptr_t)NULL - (uintptr_t)NULL defined? I know that it works in all used by me implementations. But how does it look like from the standard point of view? I cant find the clear answer. Edit: From the dupe I assume that the question one answer is: YES. What about the second and third

Namespace of a function declaration nested in function

ぃ、小莉子 提交于 2021-01-02 18:47:05
问题 For odd reasons, I want to declare a function inside a function scope. So I get the following code : namespace NS { void foo() { void bar(); bar(); } } In another compilation unit, I want to define bar. Depending on the compiler I'm using, I need to put bar in namespace NS or in the global namespace to be able to link: On clang: namespace NS { void bar() {} } On MSVC: void bar() {} What's the good behavior, if any ? As a side question, why is none of the following code compiling (on my 2

Namespace of a function declaration nested in function

∥☆過路亽.° 提交于 2021-01-02 18:36:23
问题 For odd reasons, I want to declare a function inside a function scope. So I get the following code : namespace NS { void foo() { void bar(); bar(); } } In another compilation unit, I want to define bar. Depending on the compiler I'm using, I need to put bar in namespace NS or in the global namespace to be able to link: On clang: namespace NS { void bar() {} } On MSVC: void bar() {} What's the good behavior, if any ? As a side question, why is none of the following code compiling (on my 2

Namespace of a function declaration nested in function

大憨熊 提交于 2021-01-02 18:27:31
问题 For odd reasons, I want to declare a function inside a function scope. So I get the following code : namespace NS { void foo() { void bar(); bar(); } } In another compilation unit, I want to define bar. Depending on the compiler I'm using, I need to put bar in namespace NS or in the global namespace to be able to link: On clang: namespace NS { void bar() {} } On MSVC: void bar() {} What's the good behavior, if any ? As a side question, why is none of the following code compiling (on my 2

if constexpr and dependent false static_assert is ill formed?

蹲街弑〆低调 提交于 2021-01-02 17:03:49
问题 A related question provides the example of a type-independent false in a static_assert : template<class T> void foo() { if constexpr(false) static_assert(false); } However, I am more concerned if the same thing applies to a type-dependent false . Here is the relevant quote from the standard: The program is ill-formed, no diagnostic required , if no valid specialization can be generated for a template or a substatement of a constexpr if statement within a template and the template is not

Does '#'-character have to be at the start of a line in the C preprocessor? [duplicate]

試著忘記壹切 提交于 2021-01-02 05:19:06
问题 This question already has answers here : Should preprocessor instructions be on the beginning of a line? (5 answers) Closed 5 years ago . I have programmed C for quite a while now. During this time I have learned that it is a common convention to put the "#"-character that comes before preprocessor-directives at column one. Example: #include <stdio.h> int main(void) { #ifdef MACRO1 #ifdef MACRO2 puts("defined(MACRO1) && defined(MACRO2)"); #else puts("defined(MACRO1)"); #endif #else puts("

The void type in C

眉间皱痕 提交于 2020-12-29 12:10:07
问题 The void type in C seems to be strange from various different situations. Sometimes it behaves like a normal object type, such as int or char , and sometimes it just means nothing (as it should). Look at my snippet. First of all, it seems strange that you can declare a void object, meaning you just declare nothing. Then I created an int variable and casted its result to void , discarding it: If an expression of any other type is evaluated as a void expression, its value or designator is

The void type in C

落爺英雄遲暮 提交于 2020-12-29 12:03:22
问题 The void type in C seems to be strange from various different situations. Sometimes it behaves like a normal object type, such as int or char , and sometimes it just means nothing (as it should). Look at my snippet. First of all, it seems strange that you can declare a void object, meaning you just declare nothing. Then I created an int variable and casted its result to void , discarding it: If an expression of any other type is evaluated as a void expression, its value or designator is

The implicit instantiation for a member class template when the specialization is referenced in the enclosing class template

我只是一个虾纸丫 提交于 2020-12-29 07:44:47
问题 #include <iostream> template<typename T> struct A{ template<typename U> struct B{}; B<T> b; //#2 }; //#3 int main() { A<int> a; // #1 } Consider the above code, the use of the template-id A<int> causes an implicit instantiation for specialization A<int> . According to the following rule: temp.point#4 For a class template specialization, a class member template specialization, or a specialization for a class member of a class template, if the specialization is implicitly instantiated because