komisch funktionsaufbau



  • Hallo,

    normalerweise kenne ich eine funktionsaufbau wie folgt.

    void func1()
    {
       return;
    }
    

    neulich habe ich aber source code von zlib angeschaut, darin sind manche funktionen wie folgt

    /* Reset gzip file state */
    local void gz_reset(state)
        gz_statep state;
    {
        if (state->mode == GZ_READ) {   /* for reading ... */
            state->have = 0;            /* no output data available */
            state->eof = 0;             /* not at end of file */
            state->how = LOOK;          /* look for gzip header */
            state->direct = 1;          /* default for empty file */
        }
        state->seek = 0;                /* no seek request pending */
        gz_error(state, Z_OK, NULL);    /* clear error */
        state->pos = 0;                 /* no uncompressed data yet */
        state->strm.avail_in = 0;       /* no input data yet */
    }
    

    wieso darf "gz_statep state;" dazwischen sein? verstehe ich nicht, bitte um aufklärung. Danke sehr



  • Das ist K&R Style C, also vor C89 üblich.



  • Auszug aus Wikipedia - K&R Style:

    The opening function brace of a function was placed on the line following after the declaration section and at the same indentation level as the declaration (header of the function). This is because in the original C language, argument types needed to be declared on the subsequent line (i. e., just after the header of the function), whereas when no arguments were necessary, the opening brace would not appear in the same line with the function declaration. The opening brace for function declarations was an exception to the currently basic rule stating that the statements and blocks of a function are all enclosed in the function braces.

    /* Original pre-ISO C style without function prototypes */
    int main(argc, argv)
        int   argc;
        char  *argv[];
    {
        // ...
    }
    


  • Das ist noch die alte K&R Funktionsdeklaration, s. z.B. Function declaration: K&R vs ANSI



  • danke für die Antworten, ich habe wohl erst seit neuere "version" c gelernt.



  • JnZn558 schrieb:

    danke für die Antworten, ich habe wohl erst seit neuere "version" c gelernt.

    Die "neuere" Version dürfte älter als du sein.


Anmelden zum Antworten