standards

What if an object passed into std::swap throws an exception during swapping?

痞子三分冷 提交于 2021-02-08 14:14:44
问题 The C++ standard guarantees that std::swap will throw no exception. However, what if an object to swap throws an exception during swapping? Next, how should the caller find an exception has happened? and what measures should the caller take? PS: It is very common that a constructor throws an exception. struct A { A(const A&) { throw 1; } A& operator =(const A&) { throw 2; return *this; } }; int main() { A a1, a2; std::swap(a1, a2); // An exception happened, but the caller doesn't know. // How

Why is this a forward declaration in C++?

若如初见. 提交于 2021-02-08 12:16:40
问题 I will have the following code snippet in utilA.cpp: // utilB.h namespace xm { void zoo(struct tm timeval); //<-----line 0 } // utilA.cpp #include <utilB.h> //<----line 1 #include <time.h> //<----line 2 namespace xm { void foo() { struct tm time1 = {0}; //<----line 3 } } GCC complains when compiling utilA.cpp, error: variable 'xm::tm time1' has initializer but incomplete type It seems this is because the utilA.h is using struct tm in line 0, but without include the time.h , and the compiler

Why there is no standard way to force inline in C++?

佐手、 提交于 2021-02-08 12:16:28
问题 According to the wikipedia C++ article C++ is designed to give the programmer choice, even if this makes it possible for the programmer to choose incorrectly. If it is designed this way why there is no standard way to force the compiler to inline something even if I might be wrong? Or I can ask why is inline keyword is just a hint? I think I have no choice here. In the OOP world we call methods on the objects and directly accessing members should be avoided. If we can't force the accessors to

what is libc? what are the functions it includes? how can we get the source code of it?

こ雲淡風輕ζ 提交于 2021-02-07 13:53:40
问题 As per Wikipedia there are many variants of standard C library based on operating system and compilers. Ref: http://en.wikipedia.org/wiki/C_standard_library But I want to understand that how plenty of functions which are declared in different headers(eg: stdio.h, string.h, stdlib.h etc. ) are defined in single library. Is the source code file is same for all these header files or there are different libraries for stdio.h, string.h etc? As I am beginner to programming I don't know if multiple

what is libc? what are the functions it includes? how can we get the source code of it?

亡梦爱人 提交于 2021-02-07 13:53:26
问题 As per Wikipedia there are many variants of standard C library based on operating system and compilers. Ref: http://en.wikipedia.org/wiki/C_standard_library But I want to understand that how plenty of functions which are declared in different headers(eg: stdio.h, string.h, stdlib.h etc. ) are defined in single library. Is the source code file is same for all these header files or there are different libraries for stdio.h, string.h etc? As I am beginner to programming I don't know if multiple

What is the rationale for difference between -> and . in c/c++? [duplicate]

心已入冬 提交于 2021-02-07 13:16:56
问题 This question already has answers here : Closed 10 years ago . Possible Duplicates: C++: ptr->hello(); /* VERSUS */ (*ptr).hello(); Why does C have a distinction between -> and . ? I know the difference between the member operator (.) and the member by pointer operator (->). Why did the C designers create a different operator for this access? Why can't the compiler figure it out on its own? If you always used a . does any case exist where it is ambiguous whether you mean a member or a member

What is the rationale for difference between -> and . in c/c++? [duplicate]

人走茶凉 提交于 2021-02-07 13:16:41
问题 This question already has answers here : Closed 10 years ago . Possible Duplicates: C++: ptr->hello(); /* VERSUS */ (*ptr).hello(); Why does C have a distinction between -> and . ? I know the difference between the member operator (.) and the member by pointer operator (->). Why did the C designers create a different operator for this access? Why can't the compiler figure it out on its own? If you always used a . does any case exist where it is ambiguous whether you mean a member or a member

Follow-up: What exactly is a variable in C++14/C++17?

ⅰ亾dé卋堺 提交于 2021-02-07 12:06:41
问题 As the title suggests, this question has been asked before. However, the answers pertained to C++03/0x(11). C++11 (N3337) says this about variables: [basic]/6: A variable is introduced by the declaration of a reference other than a non-static data member or of an object. The variable’s name denotes the reference or object. This may imply that variables are essentially named objects/references. However, in C++14/C++17, that last sentence was changed to The variable’s name, if any , denotes the

Are docstrings for internal functions (python) necessary? [closed]

烈酒焚心 提交于 2021-02-06 14:47:07
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . Improve this question In python we designate internal function/ private methonds with an underscore at the beginning. Should these functions be documented with docstrings(is it required?)? (the formal documentation i mean, not the one helping the code-reader to understand the

C standard regarding pointer arithmetic outside arrays

时光毁灭记忆、已成空白 提交于 2021-01-27 04:38:52
问题 I read lot of things about pointer arithmetic and undefined behavior (link, link, link, link, link). It always ends up to the same conclusion: Pointer arithmetic is well defined only on array type and between array[0] and array[array_size+1] (one element past the end is valid with regard to the C standard). My question is: Does it means that when the compiler sees a pointer arithmetic not related to any array (undefined behavior), it could emit what it want (even nothing) ? Or is it more a