Skip to content

Add examples for void type in cpp (#4331) - #1

Open
AdrianWeaver wants to merge 4 commits into
mainfrom
aweaver/cpp_void_4331
Open

AdrianWeaver wants to merge 4 commits into
mainfrom
aweaver/cpp_void_4331

Conversation

@AdrianWeaver

Copy link
Copy Markdown
Owner

Adding examples to cpp void page to comply with the description made in the above text.
Also fixing bracket to comply with code norm given as example in guidelines.
Fixes #4331

Adding examples to cpp void page to comply with the description made in the above text.

Fixes #4331

@colin-home colin-home left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AdrianWeaver Thanks for proposing an update and taking the initiative to implement it. I've made some suggestions, along with the rationale for them, in comments below.

Comment thread docs/cpp/void-cpp.md
{
std::cout << num << std::endl;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want our sample to include everything needed to compile the code, so in this case, it would need something like the following at the beginning:

// void.cpp
#include <iostream>
using namespace std;

Unfortunately, adding this much machinery has the downside of distracting from the simplicity of the sample. If we can avoid dragging in the library, we should. Something like the following captures this idea:

// void.cpp

void return_nothing()
{
    // A void function doesn't return a value.
}

Comment thread docs/cpp/void-cpp.md Outdated
void *pv; // okay
int *pint; int i;
int main() {
int main(void)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recommend this change. We should comment in the remarks that the use of void to denote an empty parameter list is a holdover from C and isn't recommended for C++ code. For more information, see C++ Core Guidelines NL.25: Don't use void as an argument type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

More explicit example for void keyword.

2 participants