In this exercise I'm using Visual Studio 2022.
Chapter 27 // Exercise 10
Make a list of C language features adopted from C++ or C with Classes (section 27.1).
Github: N/A
- Inline Functions: Initially a C++ thing, it lets you suggest to the compiler that a function should be inlined for performance.
- Single-line Comments: I believe // was first used in B, then brought back in C++ because /**/ is tedious.
- Variable Declaration Anywhere: Instead of only at the beginning of blocks, you can now declare variables anywhere in C, much like in C++.
- Mixed Declarations and Code: Kinda related to the previous one. You can intermix variable declarations with executable code.
- Boolean Type (_Bool or bool with stdbool.h): I was shocked the first time I tried to use a bool in C and found out it had to be added to the language in C89.
- Compound Literals: Lets you create temporary structures or arrays in the middle of an expression, similar to how you'd do in C++.
- Designated Initializers: A more expressive way to initialize struct or array members.
- Static Assertions (_Static_assert): Helps catch errors at compile-time based on constant expressions.
Chapter 27 // Exercise 11
Make a list of C language features not adopted by C++.
Github: N/A
Had to look these ones up. It was actually very interesting.
- Complex Number Support (_Complex and _Imaginary): C has built-in support for complex numbers, while C++ relies on the std::complex template class.
- Different Treatment of inline Functions: In C, an inline function's definition can be present in multiple translation units. In C++, inline functions have external linkage by default, but in C they have internal linkage.
- Allowing Implicit Function Declarations: Older versions of C allowed functions to be called without a previous declaration (not recommended, though!). C++ never allowed this.
- Named Address Spaces: Some C compilers for specific platforms (like embedded systems) support this feature, but it's not a part of C++.
- Non-constant Aggregate Initializers: In C, global and static aggregates can be initialized with non-constant values. C++ doesn't allow this.
No comments:
Post a Comment