Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

What is this?

Name: Anonymous 2012-11-04 22:55

>warning: conflicting types for 'something' [enabled by default]

If put the main after the functions this doesn't show up, why?

Name: Anonymous 2012-11-04 23:07

If you try to call the function before it's declared the compiler will have to guess its types.

You can put just the declaration above main() and put the definition below.



int dicks(int x);

int main(int argc, char **argv){
    if(argc < 2){
        return 1;
    }

    printf("Dicks! :%d\n", dicks(atoi(argv[1])));

    return 0;
}

int dicks(int x){
    int i;
    int j = 0;

    for(i=0; i<x; ++i){
        j += x % i;
    }

    return j;
}

Name: Anonymous 2012-11-04 23:15

>>2
Put why put main() first then?

Name: Anonymous 2012-11-05 0:56

>>2
Specifically, for compatibility with K&R C, any function that is used before a declaration is seen is silently assumed to have type int(int). As I recall, strict compatibility with C99 requires that this behavior be deprecated.

>>3
There are different styles. It is very common for C sources to put leaf functions first and leave main at the end, but not everyone prefers it. If you have functions that call one another, it will of course be impossible to avoid prototyping at least one of them.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List