yuanning

What is void param for Such as:

ReturnType SomeFunc(void);



Re: Visual C++ Language "void" param

n0n4m3

Hi,
just like
void SomeFunc(Parameter);

means that the function doesn't return any value,

ReturnType SomeFunc(void);
or
ReturnType SomeFunc();

mean that function doesn't take any parameters.





Re: Visual C++ Language "void" param

Jonathan Caves - MSFT

The is a hangover from C ... in the original C language a parameter list like f() meant that the function could take any number of arguments: so when C was standardized they need a way to specify that a function takes no parameters so that choose f(void).

In C++ a signature like f(void) is legal but is never needed.






Re: Visual C++ Language "void" param

yuanning

thanks

So it's a rather weird way of coding in C++ world now, and will be OK if neglecting it, right





Re: Visual C++ Language "void" param

Jonathan Caves - MSFT

Yes definitley: in C++ void f(void) should not be necessary: the only case in which I can think it may be necessary is if you are creating a header file that needs to be used by C.




Re: Visual C++ Language "void" param

Marius Bancila

yuanning wrote:

thanks

So it's a rather weird way of coding in C++ world now, and will be OK if neglecting it, right

I never ever put it. And if the IDE inserts that automatically, I remove it.






Re: Visual C++ Language "void" param

Simple Samples

Jonathan Caves - MSFT wrote:

The is a hangover from C ... in the original C language a parameter list like f() meant that the function could take any number of arguments: so when C was standardized they need a way to specify that a function takes no parameters so that choose f(void).

In C++ a signature like f(void) is legal but is never needed.

Are you sure I never saw void used in the parameter area like that until recently. I have had Microsoft C before it became visual and I don't remeber void being used like that until recently. I doubt that any Platform SDK samples that are still C have void used like that.

I will be very surprised if the "the function could take any number of arguments" part is correct. I have used C before it was a standard and I have not seen that.






Re: Visual C++ Language "void" param

Jonathan Caves - MSFT

100% certain: try to compile the following C program

Code Snippet

void f1();

void f2(void);

int main()

{

f1(1, 2, 3);

f2(1, 2, 3);

}

The first line is accepted and the second line generates a warning - functions are very permissive in C.






Re: Visual C++ Language "void" param

Brian Kramer

Wow, I didn't know that!