使用char作为布尔数据类型

编程入门 行业动态 更新时间:2024-10-24 04:33:57
本文介绍了使用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 derkgwen.250free/html/index.html 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 derkgwen.250free/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 workon 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 workon 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作为布尔数据类型

本文发布于:2023-10-28 23:23:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538066.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:布尔   数据类型   char

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!