在 glibc 中找不到 iso646.h

Cannot find iso646.h in glibc

我下载了 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 源中找到的唯一文件(有点像 iso646.h) (来自 gnu.org)是 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 在这里是如何定义的,或者它是在哪里定义的,所以这个文件对我来说是不可理解的。

该文件不是 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

作为对 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;
}

在阐述 Stian 关于这些文件是编译器的一部分以及在哪里可以找到它们的回答时:


有多种标准 headers 是 so-called "freestanding implementation" 的一部分。它们只做 #definetypedef,并没有声明任何实际功能;换句话说,它们 "header only" 没有任何可链接代码:

  • <float.h>
  • <iso646.h>
  • <limits.h>
  • <stdalign.h>
  • <stdarg.h>
  • <stdbool.h>
  • <stddef.h>
  • <stdint.h>
  • <stdnoreturn.h>

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

编译器可以为这些 headers 提供 "correct" 实现,而不需要任何额外的预处理器 "magic",如果这些 headers 是由库定义的,那么这是必需的.