NO

Author Topic: void as parameter function  (Read 2851 times)

Alessio

  • Guest
void as parameter function
« on: January 23, 2009, 11:30:41 AM »
Hi,

on a C++ book I've found:

Quote
The meaning of an empty function parameter list in C++ is dramatically different than in C. In C, it means all argument checking is disabled (i.e., the function call can pass any arguments it wants). In C++, it means that the function explicitly takes no arguments. Thus, C programs using this feature might cause compilation errors when compiled in C++.

The function call can pass any arguments it wants ? Sure ?
I've tested it with

Code: [Select]
#include <stdio.h>

int foo(void)
{
return 1;
}

int main(void)
{
foo("1", "3", 2);

return 0;
}

The compiler reports "Too many arguments to 'foo'".

I've misunderstood the book's quote ?
This rule was breaked by C99 standard ?

Thanks.


Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: void as parameter function
« Reply #1 on: January 23, 2009, 06:25:55 PM »
You should use func() - not func(void)...
/Pelle