正在加载图片...
1.2 Some C Conventions for Scientific Computing 17 int g(int x,int y,float z) A function that has no parameters has the parameter type list void. A function declaration (as contrasted to a function definition)is used to "introduce"a function to a routine that is going to call it.The calling routine needs to know the number and type of arguments and the type of the returned value.In a function declaration,you are allowed to omit the parameter names.Thus the declaration for the above function is allowed to be written int g(int,int,float); If a C program consists of multiple source files,the compiler cannot check the consistency of each function call without some additional assistance.The safest 超云 way to proceed is as follows: Every external function should have a single prototype declaration in a header (.h)file. The source file with the definition (body)of the function should also include the header file so that the compiler can check that the prototypes 9 in the declaration and the definition match. Every source file that calls the function should include the appropriate header (.h)file. .Optionally,a routine that calls a function can also include that function's prototype declaration internally.This is often useful when you are 三sn developing a program,since it gives you a visible reminder(checked by the compiler through the common.h file)of a function's argument types. Later,after your program is debugged,you can go back and delete the 的 supernumary internal declarations. For the routines in this book,the header file containing all the prototypes is nr.h, listed in Appendix A.You should put the statement #include nr.h at the top of every source file that contains Numerical Recipes routines.Since,more frequently than not,you will want to include more than one Numerical Recipes routine in a 人念一 10621 single source file,we have not printed this #include statement in front of this book's individual program listings,but you should make sure that it is present in your programs. As backup.and in accordance with the last item on the indented list above. we declare the function prototype of all Numerical Recipes routines that are called 腿 by other Numerical Recipes routines internally to the calling routine.(That also North makes our routines much more readable.)The only exception to this rule is that the small number of utility routines that we use repeatedly (described below)are declared in the additional header file nrutil.h,and the line #include nrutil.h is explicitly printed whenever it is needed. A final important point about the header file nr.h is that,as furnished on the diskette,it contains both ANSI C and traditional K&R-style declarations.The ANSI forms are invoked if any of the following macros are defined:__STDC__ ANSI,or NRANSI.(The purpose of the last name is to give you an invocation that does not conflict with other possible uses of the first two names.If you have an ANSI compiler,it is essential that you invoke it with one or more of these macros1.2 Some C Conventions for Scientific Computing 17 Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machine￾readable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). int g(int x, int y, float z) A function that has no parameters has the parameter type list void. A function declaration (as contrasted to a function definition) is used to “introduce” a function to a routine that is going to call it. The calling routine needs to know the number and type of arguments and the type of the returned value. In a function declaration, you are allowed to omit the parameter names. Thus the declaration for the above function is allowed to be written int g(int, int, float); If a C program consists of multiple source files, the compiler cannot check the consistency of each function call without some additional assistance. The safest way to proceed is as follows: • Every external function should have a single prototype declaration in a header (.h) file. • The source file with the definition (body) of the function should also include the header file so that the compiler can check that the prototypes in the declaration and the definition match. • Every source file that calls the function should include the appropriate header (.h) file. • Optionally, a routine that calls a function can also include that function’s prototype declaration internally. This is often useful when you are developing a program, since it gives you a visible reminder (checked by the compiler through the common .h file) of a function’s argument types. Later, after your program is debugged, you can go back and delete the supernumary internal declarations. For the routines in this book, the header file containing all the prototypes is nr.h, listed in Appendix A. You should put the statement #include nr.h at the top of every source file that contains Numerical Recipes routines. Since, more frequently than not, you will want to include more than one Numerical Recipes routine in a single source file, we have not printed this #include statement in front of this book’s individual program listings, but you should make sure that it is present in your programs. As backup, and in accordance with the last item on the indented list above, we declare the function prototype of all Numerical Recipes routines that are called by other Numerical Recipes routines internally to the calling routine. (That also makes our routines much more readable.) The only exception to this rule is that the small number of utility routines that we use repeatedly (described below) are declared in the additional header file nrutil.h, and the line #include nrutil.h is explicitly printed whenever it is needed. A final important point about the header file nr.h is that, as furnished on the diskette, it contains both ANSI C and traditional K&R-style declarations. The ANSI forms are invoked if any of the following macros are defined: __STDC__, ANSI, or NRANSI. (The purpose of the last name is to give you an invocation that does not conflict with other possible uses of the first two names.) If you have an ANSI compiler, it is essential that you invoke it with one or more of these macros
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有