standards

Does redefining a function from the standard library violate the one-definition rule?

99封情书 提交于 2020-01-01 12:08:21
问题 #include <cmath> double log(double) {return 1.0;} int main() { log(1.0); } Suppose the function log() in <cmath> is declared in global namespace (this is unspecified in fact, and we just make this assumption), then it refers to the same function as the log() function we defined. So does this code violate the one-definition rule (see here, since no diagnostic required, this code may compile in some compiler and we cannot assert if it is correct)? Note : After recent edits, this is not a

Set as default C++11 in Clang

会有一股神秘感。 提交于 2020-01-01 09:59:10
问题 The LLVM C++ compiler has full support for C++11 standard. Is there a way to set C++11 as the default standard without adding -std=c++11 compiler flag every time? I tried setting CCXFLAGS environment variable to -std=c++11 , but with no luck. 回答1: Use clang 6.0.0 or higher. The default C++ dialect is now C++14. http://releases.llvm.org/6.0.1/tools/clang/docs/ReleaseNotes.html#c-language-changes-in-clang 来源: https://stackoverflow.com/questions/21581838/set-as-default-c11-in-clang

What is “ANSI C++”?

会有一股神秘感。 提交于 2020-01-01 08:37:30
问题 I've had someone tell me that C++98 was written under ANSI before being formally standardised as ISO/IEC 14882:1998. I know that ANSI was involved with C, but I can't seem to find much in the way of proof that the phrase "ANSI C++" is terribly accurate. Is "ANSI C++" a good description for C++98? Is "ANSI C++" a good description for subsequent versions of the C++ standard? 回答1: Initially, in '89, the standardization of C++ was handled by ANSI X3J16. Starting in '91 ISO WG21 joined in. You may

When an array is created by a subexpression, what happens with the temporaries therein?

元气小坏坏 提交于 2020-01-01 07:37:24
问题 I was reading these two paragraphs of the FDIS (12.2p{4,5}): There are two contexts in which temporaries are destroyed at a different point than the end of the full-expression. The first context is when a default constructor is called to initialize an element of an array. If the constructor has one or more default arguments, the destruction of every temporary created in a default argument is sequenced before the construction of the next array element, if any. and The second context is when a

Is it undefined behavior to exceed translation limits and are there checker tools to find it?

不羁的心 提交于 2020-01-01 04:35:06
问题 ORIGINAL QUESTION: I'm searching the C90 standard for things to be aware of, when writing hignly portable code, while having low trust in the good will of the compiler vendor, and assuming that my software might kill somebody sometimes, if I do things wrong. Let's say I'm a little paranoid. At the moment I am thinking about the "Translation limits" (5.2.4.1 ANSI/ISO 9899:1990). As pointed out in the standard and in: "Does ansi C place a limit on the number of external variables in a program?"

How to make `short-circuit evaluation` also available in `fold expressions`?

我是研究僧i 提交于 2019-12-31 16:52:16
问题 #include <type_traits> #define FORWARD(arg)\ std::forward<decltype(arg)>(arg) template<typename... Args> constexpr bool AndL(Args&&... args) { return (... && FORWARD(args)); } template<typename... Args> constexpr bool AndR(Args&&... args) { return (FORWARD(args) && ...); } int main() { bool* pb = nullptr; false && (*pb = true); // ok at runtime. AndL(false, (*pb = true)); // error at runtime! AndR(false, (*pb = true)); // error at runtime! } The traditional && operator supports short-circuit

How to make `short-circuit evaluation` also available in `fold expressions`?

半城伤御伤魂 提交于 2019-12-31 16:51:37
问题 #include <type_traits> #define FORWARD(arg)\ std::forward<decltype(arg)>(arg) template<typename... Args> constexpr bool AndL(Args&&... args) { return (... && FORWARD(args)); } template<typename... Args> constexpr bool AndR(Args&&... args) { return (FORWARD(args) && ...); } int main() { bool* pb = nullptr; false && (*pb = true); // ok at runtime. AndL(false, (*pb = true)); // error at runtime! AndR(false, (*pb = true)); // error at runtime! } The traditional && operator supports short-circuit

c++ only: unary minus for 0x80000000

限于喜欢 提交于 2019-12-31 02:44:06
问题 This question is supposedly for language-lawyers. Suppose that signed and unsigned int are both 32 bits wide. As stated in the n3337.pdf draft, 5.3.1.8, (-(0x80000000u)) = 0x100000000u-0x80000000u = 0x80000000u But I can not find the answer to the question: what will be unary minus for signed 0x80000000? Is it UB, implementation defined, or ... ? The question is mostly about run-time calculation. Say signed int my_minus(signed int i) { return -i;} .... int main() { signed int a = -0x7FFFFFFF;

COALESCE or CASE more efficient and/or standard

时间秒杀一切 提交于 2019-12-31 01:57:07
问题 In terms of x compared to y. Does x comply with sql standards better? [apologies if subjective] Is x more efficient than y? Or are these scripts completely different and to be used in different contexts? x SELECT * FROM a INNER JOIN b ON COALESCE(b.columntojoin, b.alternatecolumn) = a.columntojoin y SELECT * FROM a INNER JOIN b ON (case when b.columntojoin is null then b.alternatecolumn else b.columntojoin end) = a.columntojoin 回答1: COALESCE is essentially a shorthanded CASE statement. Both

Does using leading underscores actually cause trouble?

时光毁灭记忆、已成空白 提交于 2019-12-31 01:34:52
问题 The C/C++ standard reserves all identifiers that either lead with an underscore (plus an uppercase letter if not in the global namespace) or contain two or more adjacent underscores. Example: int _myGlobal; namespace _mine { void Im__outta__control() {} int _LivingDangerously; } But what if I just don't care? What if I decide to live dangerously and use these "reserved" identifiers anyway? Just how dangerously would I be living? Have you ever actually seen a compiler or linker problem