"void" vs "()"

Posted on 1999-07-23
Medium Priority
Last Modified: 2010-05-18
What does "void" actually mean when it's passed as the only parameter to a function?  Is it the same as empty parentheses?

I am writing code to process C++ source and am trying to decide whether to treat the two the same.

Question by:miredo
LVL 23

Expert Comment

ID: 1200927
it means the same...
EMPTY  ()...:)

Expert Comment

ID: 1200928
Everyplace I've seen it it's never done anything at all. As far as I know it's pretty much the same.

Accepted Solution

cwrea earned 200 total points
ID: 1200929
Looking at a Draft version of the C++ standard (I don't have the final one handy :-) it states in section 8.3.5:

If the parameter-declaration-clause terminates with an ellipsis, the number of arguments shall be equal to or greater than the number of parameters specified; if it is empty, the function takes no arguments.  The parameter list (void) is equivalent to the empty parameter list.  Except for this special case, void shall not be a parameter type (though types derived from void such as void*, can). (etc...)

Hope this helps.


Author Comment

ID: 1200930
Yes, it helps, thanks.


Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question