ansidecl.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /* ANSI and traditional C compatibility macros
  3. Copyright 1991, 1992 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. */
  6. /* ANSI and traditional C compatibility macros
  7. ANSI C is assumed if __STDC__ is #defined.
  8. Macro ANSI C definition Traditional C definition
  9. ----- ---- - ---------- ----------- - ----------
  10. PTR `void *' `char *'
  11. LONG_DOUBLE `long double' `double'
  12. VOLATILE `volatile' `'
  13. SIGNED `signed' `'
  14. PTRCONST `void *const' `char *'
  15. ANSI_PROTOTYPES 1 not defined
  16. CONST is also defined, but is obsolete. Just use const.
  17. DEFUN (name, arglist, args)
  18. Defines function NAME.
  19. ARGLIST lists the arguments, separated by commas and enclosed in
  20. parentheses. ARGLIST becomes the argument list in traditional C.
  21. ARGS list the arguments with their types. It becomes a prototype in
  22. ANSI C, and the type declarations in traditional C. Arguments should
  23. be separated with `AND'. For functions with a variable number of
  24. arguments, the last thing listed should be `DOTS'.
  25. DEFUN_VOID (name)
  26. Defines a function NAME, which takes no arguments.
  27. obsolete -- EXFUN (name, (prototype)) -- obsolete.
  28. Replaced by PARAMS. Do not use; will disappear someday soon.
  29. Was used in external function declarations.
  30. In ANSI C it is `NAME PROTOTYPE' (so PROTOTYPE should be enclosed in
  31. parentheses). In traditional C it is `NAME()'.
  32. For a function that takes no arguments, PROTOTYPE should be `(void)'.
  33. PARAMS ((args))
  34. We could use the EXFUN macro to handle prototype declarations, but
  35. the name is misleading and the result is ugly. So we just define a
  36. simple macro to handle the parameter lists, as in:
  37. static int foo PARAMS ((int, char));
  38. This produces: `static int foo();' or `static int foo (int, char);'
  39. EXFUN would have done it like this:
  40. static int EXFUN (foo, (int, char));
  41. but the function is not external...and it's hard to visually parse
  42. the function name out of the mess. EXFUN should be considered
  43. obsolete; new code should be written to use PARAMS.
  44. For example:
  45. extern int printf PARAMS ((CONST char *format DOTS));
  46. int DEFUN(fprintf, (stream, format),
  47. FILE *stream AND CONST char *format DOTS) { ... }
  48. void DEFUN_VOID(abort) { ... }
  49. */
  50. #ifndef _ANSIDECL_H
  51. #define _ANSIDECL_H 1
  52. /* Every source file includes this file,
  53. so they will all get the switch for lint. */
  54. /* LINTLIBRARY */
  55. #if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(WIN32)
  56. /* All known AIX compilers implement these things (but don't always
  57. define __STDC__). The RISC/OS MIPS compiler defines these things
  58. in SVR4 mode, but does not define __STDC__. */
  59. #define PTR void *
  60. #define PTRCONST void *CONST
  61. #define LONG_DOUBLE long double
  62. #define AND ,
  63. #define NOARGS void
  64. #define CONST const
  65. #define VOLATILE volatile
  66. #define SIGNED signed
  67. #define DOTS , ...
  68. #define EXFUN(name, proto) name proto
  69. #define DEFUN(name, arglist, args) name(args)
  70. #define DEFUN_VOID(name) name(void)
  71. #define PROTO(type, name, arglist) type name arglist
  72. #define PARAMS(paramlist) paramlist
  73. #define ANSI_PROTOTYPES 1
  74. #else /* Not ANSI C. */
  75. #define PTR char *
  76. #define PTRCONST PTR
  77. #define LONG_DOUBLE double
  78. #define AND ;
  79. #define NOARGS
  80. #define CONST
  81. #ifndef const /* some systems define it in header files for non-ansi mode */
  82. #define const
  83. #endif
  84. #define VOLATILE
  85. #define SIGNED
  86. #define DOTS
  87. #define EXFUN(name, proto) name()
  88. #define DEFUN(name, arglist, args) name arglist args;
  89. #define DEFUN_VOID(name) name()
  90. #define PROTO(type, name, arglist) type name ()
  91. #define PARAMS(paramlist) ()
  92. #endif /* ANSI C. */
  93. #endif /* ansidecl.h */