【问题标题】:Cannot find iso646.h in glibc在 glibc 中找不到 iso646.h
【发布时间】:2016-05-23 08:15:15
【问题描述】:

我下载了glibc 的几个版本,即2.18、2.19、2.20、2.23,我试图找到文件iso646.h,但找不到。我认为它是 glibc 的标准部分,所以它应该在那里。有谁知道它为什么不存在?

但是,我在我的本地计算机上的 /usr/lib/gcc 目录中找到了它。所以我假设它是用 gcc 安装的。但我仍然不知道为什么我在 glibc 源中找不到它。我正在粘贴我在下面找到的内容:

/* Copyright (C) 1997-2014 Free Software Foundation, Inc.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.

GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
GNU General Public License for more details.

Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.

You should have received a copy of the GNU General Public License and 
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see 
<http://www.gnu.org/licenses/>.  */  

/*
 * ISO C Standard:  7.9  Alternative spellings  <iso646.h>
 */

#ifndef _ISO646_H
#define _ISO646_H

#ifndef __cplusplus
#define and     &&  
#define and_eq  &=
#define bitand  &
#define bitor   |
#define compl   ~
#define not     !
#define not_eq  !=
#define or      ||
#define or_eq   |=
#define xor     ^
#define xor_eq  ^=
#endif

#endif

编辑: 我在下载的每个 glibc 源(来自 gnu.org)中找到的唯一文件(有点类似于 iso646.h)是 conform/data /iso646.h-data 如下所示:

#if !defined ISO && !defined POSIX && !defined XPG3 && !defined XPG4
macro and 
macro and_eq
macro bitand
macro bitor
macro compl
macro not 
macro not_eq
macro or
macro or_eq
macro xor 
macro xor_eq

#if !defined ISO && !defined ISO99 && !defined ISO11
allow *_t 
#endif
#endif

但由于我不知道这里如何定义macro,也不知道它是在哪里定义的,所以这个文件对我来说是不可理解的。

【问题讨论】:

  • 你检查过路径glibc/conform/data/iso646.h-data
  • @piyushjaiswal 是的,在我提出问题之前,我实际上查看了 glibc/conform/data/iso646.h 文件,但因为我不知道 macro 是如何定义的,或者在什么文件中macro 被定义在,我无法理解该文件并且没有费心将它包含在问题中。请参阅我添加到问题中的编辑部分。

标签: c gcc glibc


【解决方案1】:

该文件不是 libc 的一部分,而是编译器。

https://gcc.gnu.org/onlinedocs/gccint/Headers.html

$ find /|grep iso646.h
/usr/lib/gcc/x86_64-linux-gnu/4.8/include/iso646.h
/usr/lib/gcc/x86_64-linux-gnu/4.6/include/iso646.h

【讨论】:

  • 感谢您的链接。不知道 gcc 在编译程序时包含自己的头文件。但是根据 [link]en.wikipedia.org/wiki/C_standard_library,文件 iso646.h 自 1995 年以来一直是 libc 标准的一部分......你知道 glibc 不包含它的原因吗?
  • @jerry:看我的回答。 “实现”是编译器和库的结合,编译器维护者比库维护者更容易提供一些头文件。
  • 感谢@DevSolar +1 不知道库和编译器维护者之间存在这种协议。由于我直接从 gnu.org 下载了 glibc 源,并且它们在 glibc 中根本不包含 iso646.h,这是否意味着 glibc 维护者将始终假设 gcc 将始终包含它?
【解决方案2】:

详细说明 Stian 对这些文件作为编译器的一部分的回答,以及在哪里可以找到它们:


有各种标准标头是所谓的“独立实施”的一部分。他们只做#definetypedef,并没有声明任何实际功能;换句话说,它们是“仅标题”,没有任何可链接代码:

  • &lt;float.h&gt;
  • &lt;iso646.h&gt;
  • &lt;limits.h&gt;
  • &lt;stdalign.h&gt;
  • &lt;stdarg.h&gt;
  • &lt;stdbool.h&gt;
  • &lt;stddef.h&gt;
  • &lt;stdint.h&gt;
  • &lt;stdnoreturn.h&gt;

很可能,在某些地方甚至更容易,由编译器而不是定义这些,因为编译器知道关于它的平台和它使用的类型、它们的编码、限制、堆栈布局以及如何做变量参数列表等。

编译器可以为这些头文件提供“正确”的实现,而不需要任何额外的预处理器“魔法”,如果这些头文件是由库定义的,这将是必要的。

【讨论】:

  • 相反,所有实现(编译器)都必须支持提到的头文件,无论是独立的(嵌入式系统等)还是托管的(在操作系统之上运行)。
  • @Lundin:独立实现被明确定义为托管实现的子集。和实现!=编译器,实现==(编译器+库)。
  • 不是真的,它们是不同的,对于main等有不同的规则。我相信你参考4/6:“两种形式的一致性实现是托管和独立的。一个符合要求的托管实现应该接受任何严格符合的程序。符合的独立实现应接受任何严格符合的程序,其中库条款(第 7 条)中指定的功能的使用仅限于标准头文件的内容......“然后遵循列表在你的回答中。到目前为止,就标题而言,您可以说独立式是一个子集。
【解决方案3】:

作为对 Stian 答案的补充,另一种查找位置的方法是使用 gcc -E

/* demo.c */

#include <iso646.h>

int main(void)
{
    return 0;
}

发射:

david@debian:~$ gcc -E demo.c

# 1 "demo.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<command-line>" 2
# 1 "demo.c"
# 1 "/usr/lib/gcc/x86_64-linux-gnu/4.9/include/iso646.h" 1 3 4
# 2 "demo.c" 2

int main(void)
{
 return 0;
}

【讨论】:

    猜你喜欢
    • 2012-12-17
    • 2011-09-05
    • 2016-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多