使用char作为布尔数据类型 [英] using char as boolean data type

查看:114
本文介绍了使用char作为布尔数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


在我的linux盒子(redhat 7.2)上,我一直使用char作为布尔数据

类型。与使用int

或short int相比,为了节省字节数。


typedef char boolean;


布尔值x;

x = 1;

.....

if(x){

/ * x为真* /

}否则{

/ * x为假* /

}

}

这种用法在所有平台上都有效。我会很高兴如果这对所有Linux发行版至少都有效。


谢谢

Ram

解决方案

" Ramprasad A Padmanabhan" <我**** @ netcore.co.in>写道:

#Hello all,



#在我的linux盒子(redhat 7.2)上,我一直使用char作为布尔数据

#type。与使用int

#或short int相比,为了节省字节数。



#typedef char boolean;



#boolean x;

#x = 1;

#....





#if(x){

#/ * x为真* /

#} else {

#/ * x为假* /

#}

#}

#这种用法是否适用于所有平台。


是的。


-

Derk Gwen http://derkgwen.250free.com/html/index.html < br $>
JUSTICE!

正义死了。


" Ramprasad A Padmanabhan" <我**** @ netcore.co.in>写在

< pa **************************** @ netcore.co.in>:

typedef char boolean;

boolean x;
x = 1;
....

if(x){
/ * x是真的* /
}否则{
/ * x是假的* /
}
}
这是在所有平台上使用有效。我会很高兴,如果这对所有Linux发行版至少都有效。



我想不出任何符合的代码运行的任何问题

实现我能想到的。


如果我错了,clc常客会希望纠正我。 :)


但是,在一个类型名称后面隐藏一个简单的类型被一些程序员认为是坏的样式

- 为什么不首先使用char?


Irrwahn


-

我希望生活有一个回滚缓冲区。


Irrwahn Grausewitz写道:

" Ramprasad A Padmanabhan" <我**** @ netcore.co.in>写于
< pa **************************** @ netcore.co.in>:

typedef char boolean;

boolean x;
x = 1;
....

if(x){
/ * x是真的* /
}否则{
/ * x是假的* /
}
}
这是在所有平台上使用有效。我会很高兴如果这对至少所有Linux发行版都有效。



我无法想到在任何符合要求的
实现上运行的代码有任何问题我可以想到。

如果我错了,clc常客会希望纠正我。 :)

然而,隐藏在typename后面的简单类型被一些程序员认为是不好的风格 - 为什么不首先使用char?

Irrwahn

-
我希望生活有一个回滚缓冲区。




我的typedef只是为了避免混淆。

像char x;

x = 1;

/ *虽然它有效但似乎只有将int类型设置为1 * /
才合乎逻辑
Ram


Hello all,

On my linux box ( redhat 7.2 ), I have been using char as a boolean data
type. In order to save on the number of bytes as compared to using int
or short int.

typedef char boolean;

boolean x;
x=1;
.....
if(x){
/* x is true */
} else {
/* x is false */
}
}
Is this usage of valid on all platforms. I will be happy If this will work
on all linux distributions at least.

Thanks
Ram

解决方案

"Ramprasad A Padmanabhan" <my****@netcore.co.in> wrote:
# Hello all,
#
# On my linux box ( redhat 7.2 ), I have been using char as a boolean data
# type. In order to save on the number of bytes as compared to using int
# or short int.
#
# typedef char boolean;
#
# boolean x;
# x=1;
# ....
#
#
# if(x){
# /* x is true */
# } else {
# /* x is false */
# }
# }
# Is this usage of valid on all platforms.

Yes.

--
Derk Gwen http://derkgwen.250free.com/html/index.html
JUSTICE!
Justice is dead.


"Ramprasad A Padmanabhan" <my****@netcore.co.in> wrote in
<pa****************************@netcore.co.in>:

typedef char boolean;

boolean x;
x=1;
....
if(x){
/* x is true */
} else {
/* x is false */
}
}
Is this usage of valid on all platforms. I will be happy If this will work
on all linux distributions at least.


I cannot think of any problems with that code running on any conforming
implementation I can think of.

If I''m wrong, the c.l.c regulars will hopefully correct me. :)

However, hiding a simple type behind a typename is considered bad style
by some programmers - why not use char in the first place?

Irrwahn

--
I wish life had a scroll-back buffer.


Irrwahn Grausewitz wrote:

"Ramprasad A Padmanabhan" <my****@netcore.co.in> wrote in
<pa****************************@netcore.co.in>:

typedef char boolean;

boolean x;
x=1;
....
if(x){
/* x is true */
} else {
/* x is false */
}
}
Is this usage of valid on all platforms. I will be happy If this will work
on all linux distributions at least.



I cannot think of any problems with that code running on any conforming
implementation I can think of.

If I''m wrong, the c.l.c regulars will hopefully correct me. :)

However, hiding a simple type behind a typename is considered bad style
by some programmers - why not use char in the first place?

Irrwahn

--
I wish life had a scroll-back buffer.



I typedef is just to avoid confusion.
Like char x;
x = 1;
/* Though it works It seems logical only to have int types set to 1 */
Ram


这篇关于使用char作为布尔数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆