Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


"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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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.

664 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