"向后"用C条件语句

编程入门 行业动态 更新时间:2024-10-24 03:25:17
本文介绍了"向后"用C条件语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我期待通过一些code和我发现了一些奇怪的条件语句,即:

I'm looking through some code and I found some strange conditionals, namely:

if (NULL != buf) {...}

我想知道是否有写有条件这样一个特别的原因,而不是

I was wondering if there was a particular reason for writing the conditional like this, instead of

if(buf != NULL){...}

我看不到任何理由这样做了我的头顶部的第一种方式,但我不认为这是一个错误。对我来说,好像他们完成同样的事情,但第二个方式是方式更直观。有没有办法使用的第一个条件的一些具体原因是什么?

I can't see any reason to do it the first way off the top of my head, but I don't think it was a mistake. To me, it seems like they accomplish the same thing, but the second way is way more intuitive. Is there some specific reason to use the first conditional?

推荐答案

是的,这就是所谓的尤达条件。我们的想法是,当你的意思是做了检查,不小心分配一个值。大多数现代编译器应该抓住它。

Yes, it's called "Yoda conditions". The idea is to not accidentally assign a value when you mean to be doing a check. Most modern compilers should catch it.

更多推荐

"向后"用C条件语句

本文发布于:2023-05-25 10:56:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/226627.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语句   条件   QUOT

发布评论

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

>www.elefans.com

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