pippo

技术成长笔记

统计

留言簿

阅读排行榜

评论排行榜

Double Inclusion, Include Guard and Pragma once

C语言里如果有这么几个文件:

File "grandfather.h"
struct foo { int member; };

File "father.h"
#include "grandfather.h"

File "child.c"
#include "grandfather.h"
#include "father.h"

编译器就会报错,因为foo这个结构体被定义了两次。

通常情况下我们会用include guards来避免这样的重复定义

File "grandfather.h"

#ifndef H_GRANDFATHER
#define H_GRANDFATHER
struct foo {
    int member;
};
#endif

File "father.h"
#include "grandfather.h"

File "child.c"
#include "grandfather.h"
#include "father.h"

posted on 2006-11-20 17:30 Giuliano 阅读(117) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航:   博客园   博客园最新博文   博问   管理