鱼C论坛

 找回密码
 立即注册
查看: 3134|回复: 3

这段代码是函数吗?

[复制链接]
发表于 2019-3-17 13:21:12 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
在学习mupdf,在getopt.c文件中有段代码,是函数吗,请朋友们指教,
代码如下,有疑问的在最下面“int chr;”后面一对大括号
  1. #ifndef _NO_PROTO
  2. # define _NO_PROTO
  3. #endif
  4. #ifdef HAVE_CONFIG_H
  5. # include <config.h>
  6. #endif
  7. #if !defined __STDC__ || !__STDC__
  8. # ifndef const
  9. #  define const
  10. # endif
  11. #endif
  12. #include <stdio.h>
  13. #define GETOPT_INTERFACE_VERSION 2
  14. #if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
  15. # include <gnu-versions.h>
  16. # if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
  17. #  define ELIDE_CODE
  18. # endif
  19. #endif
  20. #ifndef ELIDE_CODE
  21. #ifdef        __GNU_LIBRARY__
  22. # include <stdlib.h>
  23. # include <unistd.h>
  24. #endif  
  25. #ifdef VMS
  26. # include <unixlib.h>
  27. # if HAVE_STRING_H - 0
  28. #  include <string.h>
  29. # endif
  30. #endif
  31. #ifndef _
  32. # if defined HAVE_LIBINTL_H || defined _LIBC
  33. #  include <libintl.h>
  34. #  ifndef _
  35. #   define _(msgid)        gettext (msgid)
  36. #  endif
  37. # else
  38. #  define _(msgid)        (msgid)
  39. # endif
  40. #endif
  41. #include "getopt.h"
  42. char *optarg;
  43. int optind = 1;
  44. int __getopt_initialized;
  45. static char *nextchar;
  46. int opterr = 1;
  47. int optopt = '?';
  48. static enum
  49. {
  50.     REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
  51. } ordering;
  52. static char *posixly_correct;
  53. #ifdef        __GNU_LIBRARY__
  54. # include <string.h>
  55. # define my_index        strchr
  56. #else
  57. # if HAVE_STRING_H
  58. #  include <string.h>
  59. # else
  60. #  include <strings.h>
  61. # endif
  62. #ifndef getenv
  63. extern char *getenv();
  64. #endif
  65. static char *
  66. my_index(str, chr)
  67. const char *str;
  68. int chr;
  69. {
  70.     while (*str)
  71.     {
  72.         if (*str == chr)
  73.             return (char *)str;
  74.         str++;
  75.     }
  76.     return 0;
  77. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-3-17 13:42:04 | 显示全部楼层
本帖最后由 jackz007 于 2019-3-17 16:42 编辑

    其中只有这些才是函数
  1. my_index(str, chr)
  2. const char *str;
  3. int chr;
  4. {
  5.     while (*str)
  6.     {
  7.         if (*str == chr)
  8.             return (char *)str;
  9.         str++;
  10.     }
  11.     return 0;
  12. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-3-17 18:14:06 | 显示全部楼层
jackz007 发表于 2019-3-17 13:42
其中只有这些才是函数

这种形式的定义,之前没看到过,哪里有相关内容介绍呢?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-3-17 18:29:02 | 显示全部楼层
本帖最后由 jackz007 于 2019-3-17 18:30 编辑
heihei_a_o 发表于 2019-3-17 18:14
这种形式的定义,之前没看到过,哪里有相关内容介绍呢?


      你贴出的这种代码中包含很多预编译指令、宏和条件编译指令,一般应该存在于头文件中,但是,头文件里一般又是不定义函数的。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-10 12:56

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表