[gameprogrammer] Re: VC++ array woes.
- From: Robbert de Groot <zekaric@xxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Wed, 25 Aug 2004 20:05:11 -0400 (EDT)
---8<---
> Yeah, putting the constant on the left side of the equality test can
> save a lot of trouble. But I don't think that was what we were talking
> about. I was talking about doing the actual assignment in the test of
> the if statement, eg:
>
> if (NULL == (tmp = (int*)malloc(sizeof(int) * size)))
> { handle error }
>
> should be:
>
> tmp = (int*)malloc(sizeof(int) * size);
> if (NULL == tmp)
> { handle error }
>
> It's cleaner and less error prone, and it gets rid of one level of
> parentheses (which is a maintenance problem).
>
> Dave.
Plus, it gets rid of a warning (at warning level 4 for VC) about "Assignment
within a contitional".
This had been one of those things that has bit us (at work) a few times
where an assignment should have been a conditional but since code was
littered with these things we couldn't see it or just ignored the warning,
(or vice versa conditional should have been and assignment.) So we don't
allow that anymore (at work) and saves us some headaches.
______________________________________________________________________
Post your free ad now! http://personals.yahoo.ca
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- References:
- [gameprogrammer] Re: VC++ array woes.
- From: Dave Slutzkin
Other related posts:
- » [gameprogrammer] VC++ array woes.
- » [gameprogrammer] Re: VC++ array woes.
- » [gameprogrammer] Re: VC++ array woes.
- » [gameprogrammer] Re: VC++ array woes.
- » [gameprogrammer] Re: VC++ array woes.
- » [gameprogrammer] Re: VC++ array woes.
- [gameprogrammer] Re: VC++ array woes.
- From: Dave Slutzkin