Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CppCoreGuidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,8 @@ We can of course pass the number of elements along with the pointer:

void g2(int n)
{
f2(new int[n], n); // bad: a wrong number of elements can be passed to f()
// bad: the wrong number of elements can be passed to f2()
f2(new int[n], n);
}

Passing the number of elements as an argument is better (and far more common) than just passing the pointer and relying on some (unstated) convention for knowing or discovering the number of elements. However (as shown), a simple typo can introduce a serious error. The connection between the two arguments of `f2()` is conventional, rather than explicit.
Expand Down