Skip to main content

Questions tagged [c++]

For questions about C++'s design, or languages which are closely related to C++

Filter by
Sorted by
Tagged with
7 votes
0 answers
171 views

Why do using-directives in C++ work the way they do?

There's already a question on StackOverflow regarding this, but I feel like this platform is more appropriate for the question. Why is it that when a using-directive is used inside a scope in C++, ...
Rajdeep Sindhu's user avatar
2 votes
0 answers
72 views

Is there a guide for implementing exceptions in languages with explicit memory management?

I'm looking for a guide for implementing exceptions in a language with explicit memory management like C++. However, the language's type system and exception handling semantics are incompatible with C+...
feldentm's user avatar
  • 1,929
7 votes
5 answers
3k views

What is the explicit list of the situations that require RAII?

RAII, the acronym for "resource acquisition is initialization", is a crucial paradigm of C++ that is meant to prevent the following things: Forgetting to free a dynamic storage Forgetting ...
Dannyu NDos's user avatar
11 votes
5 answers
674 views

Why don't languages do automatic pimpl?

In the C++ community, there is a well know compilation cascade problem, that can be solved with the pimpl ideom https://herbsutter.com/gotw/_100/ Here's the problem: If you nest structs (with each ...
Tom Huntington's user avatar
3 votes
3 answers
736 views

Why does C++'s unordered_map::erase fully invalidate iterators, not even supporting advancing?

The documentation on C++'s unordered_map::erase states: Removes specified elements from the container. The order of the remaining elements is preserved. (This ...
Luatic's user avatar
  • 330
3 votes
1 answer
235 views

Concept Overloading in C++

The meaning of function overloading is that two or more functions can have the same name but different parameters. In C++20, concept has been introduced. I found ...
JimmyHu's user avatar
  • 133
4 votes
4 answers
592 views

Why does C++ allow extra arguments to printf?

In the C++ standard library, the format and printf functions specifically accept extraneous arguments: It is not an error to ...
Deborah C's user avatar
25 votes
3 answers
6k views

Why are volatile objects so difficult to work with in C++?

C++ does not generate default copy/move constructors or assignment operators for any volatile struct or ...
Bbrk24's user avatar
  • 9,117
15 votes
4 answers
4k views

When would a Java style enum be better than a C++ style enum, and vice versa?

In Java, enum values behave like objects (since they are basically syntactic sugar for objects) and they can have their own class methods. In C++, however, enums are essentially an alias for an ...
FireTheLost's user avatar
  • 1,613
6 votes
3 answers
825 views

Why might a language avoid reallocation?

In Java, the size of arrays are immutable. However, to my understanding, they are still allocated on the heap, because Java allocates almost everything on the heap. Even then, Java arrays are still ...
CPlus's user avatar
  • 8,523
15 votes
8 answers
6k views

Why would a language need to have trap representations?

In C there is a concept of trap representations, or non-value representations. If such a value is produced or used, immediate undefined behavior is invoked. This is one of the dangers of using ...
CPlus's user avatar
  • 8,523
20 votes
4 answers
5k views

What obstacles prevented C and C++ from standardizing π?

C does not even have M_PI standardized. C++ only added std::numbers::pi very recently. Yes, the fact that this took so long does ...
CPlus's user avatar
  • 8,523
6 votes
1 answer
187 views

Automatic copy to move promotion

I'm designing a language that has move semantics similar to C++. To make it more efficient and to prevent the need for explicit moves I want to automatically promote copies to moves if the compiler ...
chrysante's user avatar
  • 778
5 votes
3 answers
626 views

What are the pros and cons of SFINAE?

SFINAE stands for Substitution Failure Is Not An Error. It's widely used by C++ in template resolution, where it has two major consequences: If a specific template instantiation is invalid, but there ...
Bbrk24's user avatar
  • 9,117
6 votes
2 answers
305 views

How are C++ style references implemented behind the scenes? Could they be implemented without pointers?

I would not be surprised if C++ style int &y = x; was no more than int *y = &x; behind the scenes and every use of ...
CPlus's user avatar
  • 8,523
7 votes
1 answer
175 views

Disjoint language extensions (C++ and Objective-C)

Objective-C and C++ are both extensions of C (or at least started out to be). So for the purpose of this question I allow myself the slightly inaccurate assumption that both languages are pure ...
chrysante's user avatar
  • 778
6 votes
2 answers
1k views

Why does C++ require private methods to be declared with public ones?

C++ and Objective-C both require forward declaration of the methods and fields on a class. Objective-C lets you hide the existence of internal/private methods & fields altogether: ...
Bbrk24's user avatar
  • 9,117
2 votes
1 answer
400 views

How does the C++ Committee generally decide what does or doesn't go in its standard library?

I want to learn from how some existing, well-known, well-established languages define their standard libraries. As a first step- before getting in to the deeper "why" questions, I want to ...
starball's user avatar
  • 1,652
7 votes
1 answer
249 views

What can be learned from problems (and associated solutions / goals to strive for) C++ committee members have identified with their proposal culture?

C++ has a proposal process for changes to the language and standard library (see also the ISO C++ wiki's page on "How To Submit a Proposal", the Std Proposals mailing list, the list of ...
starball's user avatar
  • 1,652
32 votes
9 answers
3k views

Why would a language have a concept of undefined behavior instead of raising an error?

Certain constructs or conditions in programming just are not allowed. Languages such as Java or Swift handle these by raising an error when encountered. C and C++ on the other hand say 'Anything could ...
CPlus's user avatar
  • 8,523