To void or not to void

D

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)?


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
 
A

Alf P. Steinbach /Usenet

* 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
 
B

Balog Pal

Default User said:
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.
 
D

Default User

Alf P. Steinbach /Usenet said:
* Default User, on 14.03.2011 01:23:

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top