To void or not to void

Discussion in 'C++' started by Default User, Mar 14, 2011.

  1. Default User

    Default User Guest

    Normally, in C++ one doesn't use void in a function declaration when it
    takes no parameters. You need to in C. So what about a C++ function declared
    with an extern "C"? Example:

    extern "C" void __declspec(dllexport) functionName() // does this need to be
    (void)?


    As is probably evident, this is in a Windows DLL. Right now, the entire
    program is C++. I don't know if it will ever be used with C modules.



    Brian
    Default User, Mar 14, 2011
    #1
    1. Advertising

  2. * Default User, on 14.03.2011 01:23:
    > Normally, in C++ one doesn't use void in a function declaration when it
    > takes no parameters. You need to in C. So what about a C++ function declared
    > with an extern "C"? Example:
    >
    > extern "C" void __declspec(dllexport) functionName() // does this need to be
    > (void)?
    >
    >
    > As is probably evident, this is in a Windows DLL. Right now, the entire
    > program is C++. I don't know if it will ever be used with C modules.


    In C the 'void' formal argument list tells the C compiler that this function
    does not accept any arguments.

    But the C linkage link level name doesn't tell this: by convention it doesn't
    depend on the function signature.

    And so if the above had truly produced a C convention link level name, then a
    "void" would not serve any purpose, since it's not seen by the C compiler, and
    since with true C link level names it would not affect the link level name.

    However, the above is Microsoft stuff.

    With Microsoft's conventions "extern C" does not necessarily produce C
    convention link level names. And so the answer is platform- and compiler-
    specific. I do not know that answer, but you can use a tool such as Microsoft's
    "dumpbin" to check the link-level names, or, ask in a Microsoft group (it's
    off-topic here since this group deals only with standard C++).


    Cheers & hth.,

    - Alf

    --
    blog at <url: http://alfps.wordpress.com>
    Alf P. Steinbach /Usenet, Mar 14, 2011
    #2
    1. Advertising

  3. Default User

    Balog Pal Guest

    "Default User" <>
    > Normally, in C++ one doesn't use void in a function declaration when it
    > takes no parameters. You need to in C. So what about a C++ function
    > declared with an extern "C"? Example:
    >
    > extern "C" void __declspec(dllexport) functionName() // does this need to
    > be (void)?


    If you do it this way, no. As a C compiler could not compile it anyway.

    If you have the regular layout for double-compile, where the extern "C" part
    is present with __cplusplus, then you need void for the C build to avoid
    those "not a prototype" warnings.
    Balog Pal, Mar 14, 2011
    #3
  4. Default User

    Default User Guest

    "Alf P. Steinbach /Usenet" <> wrote in
    message news:ilk04o$82l$-september.org...
    >* Default User, on 14.03.2011 01:23:
    >> Normally, in C++ one doesn't use void in a function declaration when it
    >> takes no parameters. You need to in C. So what about a C++ function
    >> declared
    >> with an extern "C"? Example:
    >>
    >> extern "C" void __declspec(dllexport) functionName() // does this need to
    >> be
    >> (void)?
    >>
    >>
    >> As is probably evident, this is in a Windows DLL. Right now, the entire
    >> program is C++. I don't know if it will ever be used with C modules.

    >
    > In C the 'void' formal argument list tells the C compiler that this
    > function does not accept any arguments.
    >
    > But the C linkage link level name doesn't tell this: by convention it
    > doesn't depend on the function signature.
    >
    > And so if the above had truly produced a C convention link level name,
    > then a "void" would not serve any purpose, since it's not seen by the C
    > compiler, and since with true C link level names it would not affect the
    > link level name.


    That's what I thought, thanks.



    Brian
    Default User, Mar 14, 2011
    #4
    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. Sergio

    returning a void (*)(void)

    Sergio, Jan 5, 2005, in forum: C++
    Replies:
    6
    Views:
    425
    Jonathan Turkanis
    Jan 5, 2005
  2. Ollej Reemt
    Replies:
    7
    Views:
    500
    Jack Klein
    Apr 22, 2005
  3. Stig Brautaset

    `void **' revisited: void *pop(void **root)

    Stig Brautaset, Oct 25, 2003, in forum: C Programming
    Replies:
    15
    Views:
    777
    The Real OS/2 Guy
    Oct 28, 2003
  4. Replies:
    5
    Views:
    815
    S.Tobias
    Jul 22, 2005
  5. Replies:
    1
    Views:
    394
    Victor Bazarov
    May 23, 2007
Loading...

Share This Page