[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?)
From: |
Pascal J . Bourguignon |
Subject: |
Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?) |
Date: |
Mon, 9 Feb 2004 18:36:25 +0100 |
David Ayers writes:
> Due to the standard C conversion rules, which may truncate the higher
> order bytes, code must insure to explicitly convert any C truth values
> into the valid BOOL values if either YES or NO.
No. Code must insure to explicitly convert any C scalar value into a
truth value, in order to be able to generate a valid BOOL value.
int a_value=4*256;
unsigned char random_value = a_value; /* THIS IS NOT A TRUTH VALUE!!! */
unsigned char my_boolean = (a_value!=0); /* must be explicit! */
> I'd say uninformed rather than careless, but maybe some sane C
> programmer can offer a patch to our coding conventions to educate us
> carelessly insane ObjC developers, by correctly and clearly stating and
> demonstrating the issue.
void PleaseWrite(bool isBetter,void* pointer,int value);
{if((!isBetter)&&(pointer!=NULL)||(value==0)){ print("Right!\n");}}
int value;
bool isCorrect=(value!=0);
value=isCorrect?1:0;
> I'd appreciate if we could get back to the discussion on whether we
> should have a public macro to warn/assert about the correct values of
> BOOL parameters and return values, so that other carelessly insane
> developers may be educated.
>
> I have no objections to stick with isYES(), but maybe a simple
> is()/_is() may be less bulky than my previous alternatives and won't be
> as hard to parse in comparisons involving NO. I'd be in favor of
> emitting a warning and "BOOLifying*" by default and possibly raising
> with NDEBUG defined (i.e. when compiled with debug=yes). If some think
> this is too harsh because there are too many carelessly insane
> developers that have produced legacy code that doesn't take care to
> convert, I'd be fine with only emitting warnings.
> * comparing with "!= NO" and returning the result.
Perhaps it could be enough to check BOOL parameter input into the API.
--
__Pascal_Bourguignon__ http://www.informatimago.com/
There is no worse tyranny than to force a man to pay for what he doesn't
want merely because you think it would be good for him.--Robert Heinlein
http://www.theadvocates.org/
- Re[2]: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), (continued)
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Kazunobu Kuriyama, 2004/02/07
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), David Ayers, 2004/02/07
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Pascal J . Bourguignon, 2004/02/07
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Nicola Pero, 2004/02/07
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Kazunobu Kuriyama, 2004/02/09
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Pascal J . Bourguignon, 2004/02/09
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), David Ayers, 2004/02/09
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Richard Frith-Macdonald, 2004/02/09
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?),
Pascal J . Bourguignon <=
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), David Ayers, 2004/02/09
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Kazunobu Kuriyama, 2004/02/09
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Pascal J . Bourguignon, 2004/02/09
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Kazunobu Kuriyama, 2004/02/10
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), David Ayers, 2004/02/10
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Alexander Malmberg, 2004/02/10
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Nicola Pero, 2004/02/10
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Kazunobu Kuriyama, 2004/02/08
Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Alexander Malmberg, 2004/02/10