C到C#条件转换问题 [英] C to C# condition conversion question

查看:89
本文介绍了C到C#条件转换问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我正在尝试将函数从C转换为C#,并且不要不理解这里发生的事情.给出以下定义:

Hi @ all!

I''m trying to convert a function to from C to C# and do not undestand what''s going on here. The following definitions are given:

int   **matrix;
char   *objects;



以后,将通过以下方式设置条件:



Later a conditions is set up in the following way:

if( objects[ matrix[i][j] ] ) 
  <dosomething>



那里检查了什么?字符可以以某种方式为布尔值?还是C样式的NULL测试?

在此先感谢

Rowan



What is checked there? A char can be boolean in some way? Or is it C style NULL testing?

Thanks in advance

Rowan

推荐答案

是的,这是C的一种方式,而不是使用不存在的布尔值.具有二进制表示形式的所有内容都填充全零(空,整数0,浮点0,字符0x00等)的所有内容都被视为false;否则,所有内容都将被视为false.以及其他所有内容-都是真实的.更确切地说,布尔类型本身甚至不存在,但是"if"用作任何类型都可以用作布尔.通常使用TRUE和FALSE定义,但它们不过是某些预处理器(预编译器)宏定义.因此,有数以百万计的错误源于比较之类的错误,例如if (value == TRUE)而不是if (value)以及许多类似的疯狂问题.一场噩梦…因此,请特别小心,尤其是与其他语言的接口.

—SA
Yes, this is kind of a way C goes instead of using Boolean, which does not exist. Everything which has binary representation filled with all zeros (null, integer 0, floating-point 0, character 0x00, etc) is considered false; and everything else — as true. More exactly, Boolean type itself does not even exist, but "if" is used as any type workes as Boolean. The definition or TRUE and FALSE is often used, but they is nothing more than some preprocessor (precompiler) macro definitions. So, there are millions of bugs stemmed from comparison like if (value == TRUE) instead of if (value) and a number of similar crazy problems. A nightmare… So, be very careful, especially interfacing with other languages.

—SA


这篇关于C到C#条件转换问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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