Why would you declare variables in the middle of defining a function?

后端 未结 2 1777
鱼传尺愫
鱼传尺愫 2021-01-29 02:49

I have to modify the code for the G722 codec made by the ITU at work.

I contains realy funky function definitions like this one :

    int 
    main (argc         


        
相关标签:
2条回答
  • 2021-01-29 03:42

    I found the answer by googling "Old C Style Declaration" like it was suggested in comments.

    The answer is :

    The old-style function declarations and definitions use slightly different rules for declaring parameters than the syntax recommended by the ANSI C standard. First, the old-style declarations don't have a parameter list. Second, in the function definition, the parameters are listed, but their types are not declared in the parameter list. The type declarations precede the compound statement constituting the function body. The old-style syntax is obsolete and should not be used in new code. Code using the old-style syntax is still supported, however.

    This is from : http://msdn.microsoft.com/en-us/library/efx873ys.aspx

    0 讨论(0)
  • 2021-01-29 03:47

    That's very old (pre-1989 standard) function definition syntax. It's still legal for backwards-compatibility's sake, but it's definitely no longer recommended.

    As to why anyone would use it, the only reasonable scenarios I can think of are:

    • this code is very old and nobody wants to risk breaking it just to bring it up to date;
    • it's hosted on a platform for which compilers for later versions of the language were never implemented;
    0 讨论(0)
提交回复
热议问题