From c1b003f404a8696285b04b6d8e0d59343f3ba07e Mon Sep 17 00:00:00 2001 From: Gaspard Bucher Date: Sat, 25 May 2024 10:18:42 +0200 Subject: [PATCH 1/4] Fix phrase related to "cout" but not relevant for print. --- 01-string-and-character-literals.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/01-string-and-character-literals.md b/01-string-and-character-literals.md index e090cea..9507653 100644 --- a/01-string-and-character-literals.md +++ b/01-string-and-character-literals.md @@ -133,7 +133,7 @@ While little hands make vain pretence Our wanderings to guide. ``` -* Now use a (non-raw) string literal for each line and a single call to `print()` with suitable escape characters. What happens if you remove all of the stream insertion operators *except* for the first? (Explanation: *concatenation* of adjacent string literals is automatically performed by the pre-processor.) +* Now use a (non-raw) string literal for each line and a single call to `print()` with suitable escape characters. You concatenate the string literals without any operator: *concatenation* of adjacent string literals is automatically performed by the pre-processor. * Modify `01-title.cpp` to output the title of your favorite book or film centered on the console window (assume an 80 character fixed width, and change the size of the console window if different). From 366822f3e77765d6f427b8f190f850211a1c98a2 Mon Sep 17 00:00:00 2001 From: Gaspard Bucher Date: Sat, 25 May 2024 12:11:06 +0200 Subject: [PATCH 2/4] Fix cast of char8_t to char. Has to use reinterpret_cast. --- 01-string-and-character-literals.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/01-string-and-character-literals.md b/01-string-and-character-literals.md index 9507653..904de69 100644 --- a/01-string-and-character-literals.md +++ b/01-string-and-character-literals.md @@ -156,7 +156,7 @@ The following table lists C++ types, sizes, target encodings, literals and objec | char32_t | 32 | UTF-32 | U"abcd" | U'a' | UR"(abcd)" | u32string | n/a | no | | wchar_t | 16/32 | n/a + | L"abcd" | L'a' | LR"(abcd)" | wstring | wcout/wcerr | no | -* An explicit cast to type `char` in `operator<<` may be required when using `cout`/`cerr`, for example: `cout << static_cast(u8"Hello \u20AC!\n");`. +* An explicit cast to type `char` in `operator<<` may be required when using `cout`/`cerr`, for example: `cout << reinterpret_cast(u8"Hello \u20AC!\n");`. + The `wchar_t` encoding and streams under Windows are 16-bit and support UTF-16. From 046376d2c8f362d07c7b780ff16e0a9925a6bf22 Mon Sep 17 00:00:00 2001 From: Gaspard Bucher Date: Sat, 25 May 2024 17:03:57 +0200 Subject: [PATCH 3/4] acos and constexpr with clang++ Removed `-lm` requirement for `acos` on MacOS. Added a comment about `acos` not being constexpr in some cmath implementations (clang++ for example). --- 02-variables-scopes-and-namespaces.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/02-variables-scopes-and-namespaces.md b/02-variables-scopes-and-namespaces.md index 90f799d..732db2b 100644 --- a/02-variables-scopes-and-namespaces.md +++ b/02-variables-scopes-and-namespaces.md @@ -468,6 +468,9 @@ In fact, `constexpr` expressions can be complex with recent compilers, as long a #include using namespace std; +// Note: currently, not all compilers mark `acos` as a +// constexpr function in cmath. The following line might +// not compile with `clang++` for example. constexpr double PI1 = acos(-1.0); constexpr double PI2 = 22.0 / 7.0; @@ -480,7 +483,7 @@ int main() { } ``` -(Hint: this program is the first to require an additional header to ``; you may need to add `-lm` to the compile command under Linux/MacOS in order to link in the math library containing the `acos()` function.) +(Hint: this program is the first to require an additional header to ``; you may need to add `-lm` to the compile command under Linux in order to link in the math library containing the `acos()` function.) **Experiment** From 25444048b17f10e3ce3acfa2607d4d9c4c0262db Mon Sep 17 00:00:00 2001 From: Gaspard Bucher Date: Sun, 26 May 2024 22:26:01 +0200 Subject: [PATCH 4/4] missing noexcept keyword in code sample The keyword needs to be on `throw_if_zero` to demonstrate termination due to uncaught exception. --- 04-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/04-functions.md b/04-functions.md index 3d0a927..fad23eb 100644 --- a/04-functions.md +++ b/04-functions.md @@ -538,7 +538,7 @@ The keyword `noexcept` is used to declare that a function is guaranteed to not t #include using namespace std; -void throw_if_zero(int i) { +void throw_if_zero(int i) noexcept { if (!i) { throw runtime_error("found a zero"); }