Skip to content

Commit d12c789

Browse files
authored
book: clarify that typeof is not a standard C++ feature (#310)
typeof was presented as a familiar feature, but it is a non-standard extension (GCC/Clang) that was only standardized in C23 and has never been part of standard C++. Add a clarifying note in both languages. Fixes #286
1 parent d470423 commit d12c789

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

book/en-us/02-usability.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,10 @@ std::cout << add20(i, j) << std::endl;
448448
449449
### decltype
450450
451-
The `decltype` keyword is used to solve the defect that the auto keyword
452-
can only type the variable. Its usage is very similar to `typeof`:
451+
The `decltype` keyword is used to solve the defect that the `auto` keyword
452+
can only deduce the type of a variable. Its usage is very similar to `typeof`,
453+
a non-standard extension long provided by some compilers (e.g. GCC and Clang)
454+
that was eventually standardized in C23 but has never been part of standard C++:
453455
454456
```cpp
455457
decltype(expression)

book/zh-cn/02-usability.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ std::cout << add20(i, j) << std::endl;
384384
385385
### decltype
386386
387-
`decltype` 关键字是为了解决 `auto` 关键字只能对变量进行类型推导的缺陷而出现的。它的用法和 `typeof` 很相似:
387+
`decltype` 关键字是为了解决 `auto` 关键字只能对变量进行类型推导的缺陷而出现的。它的用法和 `typeof` 很相似(`typeof` 是 GCC、Clang 等编译器长期提供的非标准扩展,虽然最终在 C23 中被标准化,但从未成为 C++ 的标准特性)
388388
389389
```cpp
390390
decltype(表达式)

0 commit comments

Comments
 (0)