Hello i found that only register storage class is allowed in function.But it gives error when i mae it extern auto,extern static...

Hello i found that only register storage class is allowed in function.But it gives error when i mae it extern auto,extern static...


#include<stdio.h>
int sum( int ,int,int );
int main()
{
        int a=5,b=2,c=20;
        int d;
        d=sum(a,b,c);
        printf("c=%d",d);
}
int sum(static int a,register int b,extern int c)
{
        return a+b+c;
}
int c=20;

it shows error: storage class specified for parameter ā€˜aā€™
                 storage class specified for parameter ā€˜cā€™

Also as we know that int a; whenn we write it is same as auto int a;
means auto is the default
#include<stdio.h>
int sum( int ,int,int );
int main()
{
        int a=5,b=2,c=20;
        int d;
        d=sum(a,b,c);
        printf("c=%d",d);
}
int sum(auto int a,auto int b,auto int c)
{
        return a+b+c;
}
It also gives error !!!
please explain

If you know what the storage classes are and what they mean then it's fairly obvious that they're nonsensical when applied to function parameters. What semantics where you expecting?

First off, I DO NOT get an error with the second program using gcc 3.4.5 on Windows XP. What error do you get?

#include<stdio.h>
int sum( int ,int,int );
int main()
{
        int a=5,b=2,c=20;
        int d;
        d=sum(a,b,c);
        printf("c=%d",d);
}
int sum(auto int a,auto int b,auto int c)
{
        return a+b+c;
}

For the FIRST program, I have no idea what you are trying to accomplish. My guess is that neither does the compiler, so it gave you an error. For the "static" keyword, you use that when you want a value from the first call to the function to "hang around" for the second call to the function. An example might be if you wanted to keep a running total of the overall sum of three numbers. The following program might be useful.

#include<stdio.h>
int sum( int ,int,int );
int main()
{
        int a=5,b=2,c=20;
        int d;
        d=sum(a,b,c);
        printf("c=%d",d);
        d=sum(a,b,c);
        printf("c=%d",d);
        d=sum(a,b,c);
        printf("c=%d",d);
}


int sum(int a, int b, int c)
{
    static int total = 0;
    total += (a + b + c);
    return total;
}

Maybe you work three days a week and a, b, and c are the number of hours you worked on days 1, 2, and 3, and you're interested in the cumulative time you've worked so far. That might be a legitimate use of the word "static". I've never seen "static" in front of the parameter name as you have it. Ditto "extern". My guess is the compiler has no idea what you're trying ti do with it, as I do not. As far as "register" goes, the compiler doesn't seem to have a problem with it. "register" is one of those optimization options you can use if you really understand things on a hardware level and want to use that knowledge to speed your program up. I've never used it myself and I imagine most mere mortals should not use it either.

With static & extern it will give error as for them at compile time memory allocated...
& for auto i think it may be compiler depended i m using gcc compiler in Linux.
i m getting erroe ...
Any way thanks

This article has been dead for over six months. Start a new discussion instead.