473,580 Members | 2,899 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"void Method()" vs "void Method(void)"

Hello,

I would like to know if there is a difference in c++ between the
following two method-declarations:

void Method();

and

void Method(void);
I know there is a difference in C (the first case means the function may
have parameters, but they are not yet defined?).
But how is the semantik in C++? Is there a difference or are both
declarations equal in _every_ case?

I would be glad to get an answer to this question (and perhaps a
reference where this topic is explained (C++-standard?)).

Regards
ollej
Jul 23 '05 #1
7 2567

"Ollej Reemt" <ol***@gmx.de > wrote in message
news:d4******** @news.Informati k.Uni-Oldenburg.DE...
Hello,

I would like to know if there is a difference in c++ between the
following two method-declarations:

void Method();

and

void Method(void);


They are same. Former is the preferred type in C++. Reference to the
Standard --

8.3.5/2 - "...If the parameter-declaration-clause is empty, the function
takes no arguments. The parameter list (void) is equivalent to the empty
parameter list."

Sharad
Jul 23 '05 #2
Ollej Reemt wrote:
Hello,

I would like to know if there is a difference in c++ between the
following two method-declarations:

void Method();

and

void Method(void);
I know there is a difference in C (the first case means the function may
have parameters, but they are not yet defined?).
But how is the semantik in C++? Is there a difference or are both
declarations equal in _every_ case?

I would be glad to get an answer to this question (and perhaps a
reference where this topic is explained (C++-standard?)).

Regards
ollej


In addition to Sharad's reply, I prefer the latter method since
it is explicit and works in both languages.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
Jul 23 '05 #3
Hello Sharad and Thomas,

thanks for your answers, that was exactly what I wanted to know.

Regards
ollej
Jul 23 '05 #4
Thomas Matthews wrote:
I know there is a difference in C (the first case means the function may
have parameters, but they are not yet defined?).
But how is the semantik in C++? Is there a difference or are both
declarations equal in _every_ case?

I would be glad to get an answer to this question (and perhaps a
reference where this topic is explained (C++-standard?)).

Regards
ollej


In addition to Sharad's reply, I prefer the latter method since
it is explicit and works in both languages.


The point about it working in both languages is valid - if you make a header
that is supposed to be used in both languages, but how is it explicit?
IMHO, if you want to say "no parameters", the most explicit way to describe
that is by putting no parameters between the parens, not by putting a fake
parameter of type void there.

Jul 23 '05 #5
Rolf Magnus wrote:
Thomas Matthews wrote:
I know there is a difference in C (the first case means the
function may have parameters, but they are not yet defined?).
But how is the semantik in C++? Is there a difference or are both
declarations equal in _every_ case?

I would be glad to get an answer to this question (and perhaps a
reference where this topic is explained (C++-standard?)).

Regards
ollej


In addition to Sharad's reply, I prefer the latter method since
it is explicit and works in both languages.


The point about it working in both languages is valid - if you make a
header that is supposed to be used in both languages, but how is it
explicit? IMHO, if you want to say "no parameters", the most explicit
way to describe that is by putting no parameters between the parens,
not by putting a fake parameter of type void there.


I believe 'explicit' in this case refers to what Ollej originally said:
in C, an empty parameter list does not necessarily mean that the
function takes no arguments. In a header file shared between C and C++
code, foo(void) will *explicitly* tell either language that foo takes
no arguments. Writing foo() will only explicitly say that to C++ code.

Kristo

Jul 23 '05 #6
Kristo wrote:
Rolf Magnus wrote:
Thomas Matthews wrote:

I know there is a difference in C (the first case means the
function may have parameters, but they are not yet defined?).
But how is the semantik in C++? Is there a difference or are both
declaration s equal in _every_ case?

I would be glad to get an answer to this question (and perhaps a
reference where this topic is explained (C++-standard?)).

Regards
ollej

In addition to Sharad's reply, I prefer the latter method since
it is explicit and works in both languages.


The point about it working in both languages is valid - if you make a
header that is supposed to be used in both languages, but how is it
explicit? IMHO, if you want to say "no parameters", the most explicit
way to describe that is by putting no parameters between the parens,
not by putting a fake parameter of type void there.

I believe 'explicit' in this case refers to what Ollej originally said:
in C, an empty parameter list does not necessarily mean that the
function takes no arguments. In a header file shared between C and C++
code, foo(void) will *explicitly* tell either language that foo takes
no arguments. Writing foo() will only explicitly say that to C++ code.


And what Rolf said is still true: in English having something to designate
nothing is the source of confusion. Haven't you seen (in the Standard, no
less) pages, where the only _content_ is "this page is left intentionally
blank". Isn't it a self-contradictory statement? That's what "explicitly
emtpy argument list" means in C++: no arguments, nothing between the
opening parenthesis and the closing one. I actually strongly agree with
Rolf on this one. To be _explicit_, one should simply have bare parens.

V
Jul 23 '05 #7
On Wed, 20 Apr 2005 14:43:57 -0400, Victor Bazarov
<v.********@com Acast.net> wrote in comp.lang.c++:
Kristo wrote:
Rolf Magnus wrote:
Thomas Matthews wrote:
>I know there is a difference in C (the first case means the
>function may have parameters, but they are not yet defined?).
>But how is the semantik in C++? Is there a difference or are both
>declaration s equal in _every_ case?
>
>I would be glad to get an answer to this question (and perhaps a
>reference where this topic is explained (C++-standard?)).
>
>Regards
>ollej

In addition to Sharad's reply, I prefer the latter method since
it is explicit and works in both languages.

The point about it working in both languages is valid - if you make a
header that is supposed to be used in both languages, but how is it
explicit? IMHO, if you want to say "no parameters", the most explicit
way to describe that is by putting no parameters between the parens,
not by putting a fake parameter of type void there.

I believe 'explicit' in this case refers to what Ollej originally said:
in C, an empty parameter list does not necessarily mean that the
function takes no arguments. In a header file shared between C and C++
code, foo(void) will *explicitly* tell either language that foo takes
no arguments. Writing foo() will only explicitly say that to C++ code.


And what Rolf said is still true: in English having something to designate
nothing is the source of confusion. Haven't you seen (in the Standard, no
less) pages, where the only _content_ is "this page is left intentionally
blank". Isn't it a self-contradictory statement? That's what "explicitly
emtpy argument list" means in C++: no arguments, nothing between the
opening parenthesis and the closing one. I actually strongly agree with
Rolf on this one. To be _explicit_, one should simply have bare parens.

V


Once upon a time, I wrote the users manual for a product. I generated
some of the illustrations from AutoCAD drawings of some of the
mechanical parts. As a joke, I created one drawing of a part cracked
in half to go along with the text warning the user about doing
something that could cause damage.

The powers that be saw it, decided it was funny, and wanted it in the
manual. Then at the very last minute, they changed their mind and
wanted it out.

So when the manual was printed, it had several of those pages that
said "this page intentionally blank", and one page, the one that had
held that particular illustration, that said "this page
unintentionally left blank."

Nobody ever noticed.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

188
17294
by: infobahn | last post by:
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
7
2477
by: sunglo | last post by:
My doubt comes from trying to understand how thread return values work (I know, it's off topic here), and I'm wondering about the meaning of the "void **" parameter that pthread_join expects (I think this is topical, since it's a C question, but please correct me and apologies if I'm wrong). I suppose that it's this way to allow for...
9
3509
by: Igor Okulist | last post by:
int func(void**); { short* p = NULL; func(&p); //<<< here } Could somebody remind me why is this not allowed ? error message: "cannot convert parameter from 'short **' to 'void **'"
1
2255
by: hpandey | last post by:
sigaction : using "void (*sa_sigaction)(int, siginfo_t *, void *);" -------------------------------------------------------------------------------- hello, in sigaction manpage it's written : sa_sigaction also specifies the action to be associated with signum. This function receives the signal number as its first argument, a pointer...
7
3630
by: =?Utf-8?B?cmFtbzk5NDE=?= | last post by:
Hi, Is there any way disable using "protected override void OnPaint(..." method out of the assembly. I create usercontrol and i do not want user adds extra codes OnPaint method for securtity purpose. And i don't give a permission to call "CreateGraphics()". Thanks your responses.
0
7854
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7783
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8132
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6533
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5665
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5349
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3790
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3806
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1394
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.