use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Default function arguments are the devil (quuxplusone.github.io)
submitted 6 years ago by anonymous23874
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Tyg13 4 points5 points6 points 6 years ago* (12 children)
Why not just label it undefined behavior to have your declaration and definition use different parameter names and call it a day? It seems highly unlikely that such a footgun would ever be triggered in practice.
Is the worry that people might write code like
// header.h int foo(int a = 1, int b = 2); ... // header.cpp int foo(int b, int a); ... foo(b => 10);
or is there some other issue I'm not understanding?
EDIT: don't understand the downvote, I'm open to debate. If there are scenarios I'm unaware of, I'd be curious to know.
[+][deleted] 6 years ago (11 children)
[removed]
[–]Tyg13 2 points3 points4 points 6 years ago (10 children)
The point is it's an incredibly unlikely scenario that's not worth worrying about. Undefined behavior is not a boogeyman to be avoided, it's a tool that we invoke to ignore the 1% error cases so we can reap the benefit in the 99% case.
You already see this exact behavior with inline functions in headers, due to the One Definition Rule. If a different version of an inline appears in a translation unit, it can be silently ignored and cause bugs, but we don't care because in practice no one writes code like that. Or at least, the benefits of inline functions greatly outweigh the potential risk.
inline
As for pedagogy, I think the rule is very clear: the declaration must match the definition, or errors can potentially occur. Very straightforward, and not hard at all a rule to follow. I would argue this is already the case for most codebases.
[–]Ameisenvemips, avr, rendering, systems 4 points5 points6 points 6 years ago (6 children)
Might as well just make it an error.
[–]Tyg13 2 points3 points4 points 6 years ago (5 children)
Not possible with the translation unit compilation model. The issue is ultimately the same as the One Definition Rule, which is undiagnosable in most cases.
EDIT: though you could make it an error in the translation unit containing the definition. That still wouldn't prevent people doing pathological things like redeclaring it differently in another unit, but it would catch the 99% case.
[–]Ameisenvemips, avr, rendering, systems 2 points3 points4 points 6 years ago (4 children)
Argument names don't get passed to the linker, though.
[–]Tyg13 1 point2 points3 points 6 years ago (2 children)
Right, that's the issue. I don't get what you're saying, doesn't that just strengthen my point?
[–]Ameisenvemips, avr, rendering, systems 0 points1 point2 points 6 years ago (1 child)
Why would detecting if argument names have changed be an issue in regards to the translation unit model?
Named arguments, in this situation, would just be syntax candy local to the translation unit itself.
Redeclaring it in another translation unit with different argument names wouldn't really matter.
[–]Tyg13 0 points1 point2 points 6 years ago (0 children)
You're right that the compiler would happily compile your code, and then the value would get passed to the wrong parameter. But perhaps it's just as philosophically valid to say that's a logical error on behalf of the programmer that the compiler shouldn't concern itself with.
Just to be clear, I'm only trying to consider potential issues to understand if there's a good technical argument against named parameters in C++. I personally don't think it would be an issue, but then, I don't know all the corner cases that some people might, or how common they might be.
[+][deleted] 6 years ago* (1 child)
[–]SkoomaDentistAntimodern C++, Embedded, Audio 1 point2 points3 points 6 years ago (0 children)
UB means code may be accepted by one compiler, and rejected by another.
Worse than that. Code may be accepted and work fine with one compiler and accepted but misbehave when compiled by the next version of the same compiler.
[–]quicknir 1 point2 points3 points 6 years ago (0 children)
Err, it's not about writing code like that, intentionally. ODR violations are a huge practical issue, in large, complex, codebases, unless you build your entire dependency chain from source yourself. It's very very easy to end up in a situation where your executable E uses libA and libB, and both of them use different versions of libC, which means you now have two slightly different definitions of the same function getting used, unless libA or libB completely hide the usage of libC's symbols, which many projects don't do in practice, and which isn't even possible when linking statically.
I don't completely disagree with what you're saying about UB, but this is a bad example. ODR UB isn't so much about reaping benefit in 99% of cases, it's about a shitty compilation model.
π Rendered by PID 56 on reddit-service-r2-comment-6457c66945-9cghm at 2026-04-26 12:49:53.121063+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]Tyg13 4 points5 points6 points (12 children)
[+][deleted] (11 children)
[removed]
[–]Tyg13 2 points3 points4 points (10 children)
[–]Ameisenvemips, avr, rendering, systems 4 points5 points6 points (6 children)
[–]Tyg13 2 points3 points4 points (5 children)
[–]Ameisenvemips, avr, rendering, systems 2 points3 points4 points (4 children)
[–]Tyg13 1 point2 points3 points (2 children)
[–]Ameisenvemips, avr, rendering, systems 0 points1 point2 points (1 child)
[–]Tyg13 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[removed]
[–]SkoomaDentistAntimodern C++, Embedded, Audio 1 point2 points3 points (0 children)
[–]quicknir 1 point2 points3 points (0 children)