Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > To void or not to void

Reply
Thread Tools

To void or not to void

 
 
Default User
Guest
Posts: n/a
 
      03-14-2011
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


 
Reply With Quote
 
 
 
 
Alf P. Steinbach /Usenet
Guest
Posts: n/a
 
      03-14-2011
* 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>
 
Reply With Quote
 
 
 
 
Balog Pal
Guest
Posts: n/a
 
      03-14-2011
"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.

 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      03-14-2011
"Alf P. Steinbach /Usenet" <alf.p.steinbach+> wrote in
message news:ilk04o$82l$...
>* 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the difference between void proba(); and void proba(void); ??? PencoOdStip@gmail.com C++ 1 05-23-2007 07:12 PM
what is the difference, void func(void) and void fucn() noblesantosh@yahoo.com C Programming 5 07-22-2005 04:38 PM
"void Method()" vs "void Method(void)" Ollej Reemt C++ 7 04-22-2005 03:47 AM
returning a void (*)(void) Sergio C++ 6 01-05-2005 08:30 PM
`void **' revisited: void *pop(void **root) Stig Brautaset C Programming 15 10-28-2003 09:03 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57