鱼C论坛

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

这段代码是函数吗?

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

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

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

x
在学习mupdf,在getopt.c文件中有段代码,是函数吗,请朋友们指教,
代码如下,有疑问的在最下面“int chr;”后面一对大括号
#ifndef _NO_PROTO
# define _NO_PROTO
#endif
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#if !defined __STDC__ || !__STDC__
# ifndef const
#  define const
# endif
#endif
#include <stdio.h>
#define GETOPT_INTERFACE_VERSION 2
#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
# include <gnu-versions.h>
# if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
#  define ELIDE_CODE
# endif
#endif
#ifndef ELIDE_CODE
#ifdef        __GNU_LIBRARY__
# include <stdlib.h>
# include <unistd.h>
#endif  
#ifdef VMS
# include <unixlib.h>
# if HAVE_STRING_H - 0
#  include <string.h>
# endif
#endif
#ifndef _
# if defined HAVE_LIBINTL_H || defined _LIBC
#  include <libintl.h>
#  ifndef _
#   define _(msgid)        gettext (msgid)
#  endif
# else
#  define _(msgid)        (msgid)
# endif
#endif
#include "getopt.h"
char *optarg;
int optind = 1;
int __getopt_initialized;
static char *nextchar;
int opterr = 1;
int optopt = '?';
static enum
{
    REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
} ordering;
static char *posixly_correct;
#ifdef        __GNU_LIBRARY__
# include <string.h>
# define my_index        strchr
#else
# if HAVE_STRING_H
#  include <string.h>
# else
#  include <strings.h>
# endif
#ifndef getenv
extern char *getenv();
#endif
static char *
my_index(str, chr)
const char *str;
int chr;
{
    while (*str)
    {
        if (*str == chr)
            return (char *)str;
        str++;
    }
    return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

    其中只有这些才是函数
my_index(str, chr)
const char *str;
int chr;
{
    while (*str)
    {
        if (*str == chr)
            return (char *)str;
        str++;
    }
    return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

这种形式的定义,之前没看到过,哪里有相关内容介绍呢?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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


      你贴出的这种代码中包含很多预编译指令、宏和条件编译指令,一般应该存在于头文件中,但是,头文件里一般又是不定义函数的。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-10-3 12:27

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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