Skip to content

Commit a6afcac

Browse files
authoredMay 27, 2024
Fix phrase related to "cout" but not relevant for print. (#4)
* Fix phrase related to "cout" but not relevant for print. * Fix cast of char8_t to char. Has to use reinterpret_cast. * 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). * missing noexcept keyword in code sample The keyword needs to be on `throw_if_zero` to demonstrate termination due to uncaught exception.
1 parent 12a6bc4 commit a6afcac

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed
 

‎01-string-and-character-literals.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ While little hands make vain pretence
133133
Our wanderings to guide.
134134
```
135135

136-
* 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.)
136+
* 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.
137137

138138
* 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).
139139

@@ -156,7 +156,7 @@ The following table lists C++ types, sizes, target encodings, literals and objec
156156
| char32_t | 32 | UTF-32 | U"abcd" | U'a' | UR"(abcd)" | u32string | n/a | no |
157157
| wchar_t | 16/32 | n/a + | L"abcd" | L'a' | LR"(abcd)" | wstring | wcout/wcerr | no |
158158

159-
&#42; An explicit cast to type `char` in `operator<<` may be required when using `cout`/`cerr`, for example: `cout << static_cast<char>(u8"Hello \u20AC!\n");`.
159+
&#42; An explicit cast to type `char` in `operator<<` may be required when using `cout`/`cerr`, for example: `cout << reinterpret_cast<const char*>(u8"Hello \u20AC!\n");`.
160160

161161
&#43; The `wchar_t` encoding and streams under Windows are 16-bit and support UTF-16.
162162

‎02-variables-scopes-and-namespaces.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,9 @@ In fact, `constexpr` expressions can be complex with recent compilers, as long a
468468
#include <cmath>
469469
using namespace std;
470470

471+
// Note: currently, not all compilers mark `acos` as a
472+
// constexpr function in cmath. The following line might
473+
// not compile with `clang++` for example.
471474
constexpr double PI1 = acos(-1.0);
472475
constexpr double PI2 = 22.0 / 7.0;
473476

@@ -480,7 +483,7 @@ int main() {
480483
}
481484
```
482485
483-
(Hint: this program is the first to require an additional header to `<print>`; 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.)
486+
(Hint: this program is the first to require an additional header to `<print>`; you may need to add `-lm` to the compile command under Linux in order to link in the math library containing the `acos()` function.)
484487
485488
**Experiment**
486489

‎04-functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ The keyword `noexcept` is used to declare that a function is guaranteed to not t
538538
#include <stdexcept>
539539
using namespace std;
540540
541-
void throw_if_zero(int i) {
541+
void throw_if_zero(int i) noexcept {
542542
if (!i) {
543543
throw runtime_error("found a zero");
544544
}

0 commit comments

Comments
 (0)
Please sign in to comment.