当前位置:   article > 正文

两种头文件包含函数的区别_in file included from main.c

in file included from main.c

两种头文件包含函数的区别

In file included from main.c:3:
b/test.h:3: warning: "PI" redefined
    3 | #define PI 3.1415926
      | 
In file included from main.c:2:
a/test.h:3: note: this is the location of the previous definition
    3 | #define PI 3.14
      | 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

在多个目录下定义头文件时如果有相同头文件时候#pragma once会警告并且把后面的覆盖前面的,而#ifndef则不会进入第二个。

main.c

#include <stdio.h>
#include "a/test.h"
#include "b/test.h"

int main(int argc, char const *argv[])
{
    printf("%lf\n",PI);
    return 0;
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

a/test.h

#pragma once

#define PI 3.14

// #ifndef _TEST_H_
// #define _TEST_H_
  • 1
  • 2
  • 3
  • 4
  • 5
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/201169
推荐阅读
相关标签
  

闽ICP备14008679号