Chinaunix首页 | 论坛 | 博客
  • 博客访问: 277623
  • 博文数量: 42
  • 博客积分: 590
  • 博客等级: 中士
  • 技术积分: 447
  • 用 户 组: 普通用户
  • 注册时间: 2011-05-04 01:15
个人简介

健康快乐 虚怀若谷 淡定从容

文章分类

全部博文(42)

分类: C/C++

2011-05-16 16:45:41

C99中支持bool、true和false,头文件内容如下:
 
/* Copyright (C) 1998, 1999, 2000 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 2, 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.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING.  If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */
/* As a special exception, if you include this header file into source
   files compiled by GCC, this header file does not by itself cause
   the resulting executable to be covered by the GNU General Public
   License.  This exception does not however invalidate any other
   reasons why the executable file might be covered by the GNU General
   Public License.  */
/*
 * ISO C Standard:  7.16  Boolean type and values 
 */
#ifndef _STDBOOL_H
#define _STDBOOL_H
#ifndef __cplusplus
#define bool _Bool
#define true 1
#define false 0
#else /* __cplusplus */
/* Supporting in C++ is a GCC extension.  */
#define _Bool bool
#define bool bool
#define false false
#define true true
#endif /* __cplusplus */
/* Signal that all the definitions are present.  */
#define __bool_true_false_are_defined 1
#endif /* stdbool.h */
 
 
 今天下午在c-free5.0中调试一个代码,当用枚举方式定义bool、true和false时,却无法得出正确的结果,而通过引用头文件调用那些关键字时却能输出正确的结果,感觉很神奇,枚举定义如下:
typedef enum bool{false,true} bool;
或 typedef enum bool{false= 0,true = 0} bool;
 
这两种定义方式都不能使代码输出正确的结果。


 
阅读(3178) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~