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

Discussion in 'C++' started by Ollej Reemt, Apr 20, 2005.

  1. Ollej Reemt

    Ollej Reemt Guest

    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
     
    Ollej Reemt, Apr 20, 2005
    #1
    1. Advertising

  2. Ollej Reemt

    Sharad Kala Guest

    "Ollej Reemt" <> wrote in message
    news:d458o7$-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
     
    Sharad Kala, Apr 20, 2005
    #2
    1. Advertising

  3. 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.learn.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
     
    Thomas Matthews, Apr 20, 2005
    #3
  4. Ollej Reemt

    Oliver Robbe Guest

    Hello Sharad and Thomas,

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

    Regards
    ollej
     
    Oliver Robbe, Apr 20, 2005
    #4
  5. Ollej Reemt

    Rolf Magnus Guest

    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.
     
    Rolf Magnus, Apr 20, 2005
    #5
  6. Ollej Reemt

    Kristo Guest

    Re: "void Method()" vs "void Method(void)"

    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
     
    Kristo, Apr 20, 2005
    #6
  7. Re: "void Method()" vs "void Method(void)"

    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
    >>>>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.


    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
     
    Victor Bazarov, Apr 20, 2005
    #7
  8. Ollej Reemt

    Jack Klein Guest

    Re: "void Method()" vs "void Method(void)"

    On Wed, 20 Apr 2005 14:43:57 -0400, Victor Bazarov
    <> 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
    > >>>>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.

    >
    > 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.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, Apr 22, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Crouchez

    void method()

    Crouchez, Nov 7, 2007, in forum: Java
    Replies:
    31
    Views:
    1,082
    Roedy Green
    Nov 8, 2007
Loading...

Share This Page