[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 4/7] a trivial code change for more idiomatic wr
From: |
Peter Maydell |
Subject: |
Re: [Qemu-devel] [PATCH 4/7] a trivial code change for more idiomatic writing style |
Date: |
Thu, 31 Jul 2014 14:59:45 +0100 |
On 31 July 2014 14:55, Dr. David Alan Gilbert <address@hidden> wrote:
> * address@hidden (address@hidden) wrote:
>> --- a/qdev-monitor.c
>> +++ b/qdev-monitor.c
>> @@ -694,7 +694,7 @@ void qmp_device_del(const char *id, Error **errp)
>> DeviceState *dev;
>>
>> dev = qdev_find_recursive(sysbus_get_default(), id);
>> - if (NULL == dev) {
>> + if (dev == NULL) {
>
> I know people who write it as 'NULL == dev' on purpose,
> because that will cause an error if you accidentally type a single =
> where as 'dev = NULL' will just cause confusion.
Yes, this is the motivation for Yoda conditionals. But it only
makes sense if you don't have a compiler with a sensible
warning configuration. For QEMU you will get an error if you
write "dev = NULL" :
error: suggest parentheses around assignment used as truth value
[-Werror=parentheses]
so we don't need to get people to contort their code like this.
thanks
-- PMM
- [Qemu-devel] [PATCH for-2.2 0/7] a trivial code change for more idiomatic writing style, arei.gonglei, 2014/07/31
- [Qemu-devel] [PATCH 1/7] usb: a trivial code change for more idiomatic writing style, arei.gonglei, 2014/07/31
- [Qemu-devel] [PATCH 6/7] vl: a trivial code change for more idiomatic writing style, arei.gonglei, 2014/07/31
- [Qemu-devel] [PATCH 7/7] vmxnet3: a trivial code change for more idiomatic writing style, arei.gonglei, 2014/07/31
- [Qemu-devel] [PATCH 5/7] spice: a trivial code change for more idiomatic writing style, arei.gonglei, 2014/07/31
- [Qemu-devel] [PATCH 4/7] a trivial code change for more idiomatic writing style, arei.gonglei, 2014/07/31
- [Qemu-devel] [PATCH 3/7] isa-bus: a trivial code change for more idiomatic writing style, arei.gonglei, 2014/07/31
- [Qemu-devel] [PATCH 2/7] audio: a trivial code change for more idiomatic writing style, arei.gonglei, 2014/07/31
- Re: [Qemu-devel] [PATCH for-2.2 0/7] a trivial code change for more idiomatic writing style, Peter Maydell, 2014/07/31