大家好, 在我的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作为布尔数据类型
发布评论