xGen February 2016

Error - Too many arguments to function - long argument

I took a code snippet from a live project (which works fine) and trying to debug but gives this error.

#include <iostream>
#include <stdio.h>
#include <time.h>

using namespace std;

long aaa();

int main() {
    long greg_out = aaa(1160208);
    printf("greg_out = %ld\n", greg_out);
    return 0;
}

long aaa(date)
long date;
{
    /*Code */
} 

The error is that the declaration does not have parameter date while the method body has.

The working code is exactly same. long aaa is declared without parameter. then Parameter date(which is a numeric value of date) is defined in the method body. I am not good in C programming. I need to convert this small code into another language so trying to figure out the logic.

The answers below are also giving same solution- To declare date. But i am curious how does this code work? Is it C language itself. or any variant of C?

tried to run here http://cpp.sh/

Answers


Sourav Ghosh February 2016

In your case, the forward declaration says

 long aaa();

while your definition is

 long aaa(date)
 long date;
 {

which are diferent. Change your forward declaration to

 long aaa(long);


chqrlie February 2016

You are mixing old style C declarations and C++ constructs, this is incorrect. You should put the real signature in the forward declaration and in the definition of function aaa:

#include <iostream>
#include <stdio.h>
#include <time.h>

using namespace std;

long aaa(long);

int main() {
    long greg_out = aaa(1160208);
    printf("greg_out = %ld\n", greg_out);
    return 0;
}

long aaa(long date) {
    /*Code */
}


Rishikesh Raje February 2016

The function declaration is long aaa(); This gives a function which returns long with indeterminate arguments.

When used long greg_out = aaa(1160208); indicates a function which takes long type as argument and returns long.

Lower below, you have long aaa(date)

This, is in disagreement with the usage above. You should change it to long aaa(long)

It is not necessary, but good practice to move the declaration to the top and remove the second declaration.

Post Status

Asked in February 2016
Viewed 2,396 times
Voted 8
Answered 3 times

Search




Leave an answer