Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: David Brown Newsgroups: sci.electronics.design Subject: Re: Arduino / compilers on uC Date: Wed, 08 Feb 2017 12:40:25 +0100 Organization: A noiseless patient Spider Lines: 51 Message-ID: References: <4bd745cb-5d48-4573-9a63-a9eec5a39b0d@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Injection-Date: Wed, 8 Feb 2017 11:38:38 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="aac8a8afec3dd03b3e63b75c4406aa2d"; logging-data="16350"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/OXUy7FHRxOj0j/dQA4LFnCPMBKQIoPNQ=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: Cancel-Lock: sha1:6dPQma1W8mox3++9/RpqODYu7SQ= Xref: csiph.com sci.electronics.design:446767 On 07/02/17 23:11, M Philbrook wrote: > In article , > dagmargoodboat@yahoo.com says... >> No, I was trying to mask the upper bits. But logical operations >> didn't work either -- both 0xff and 0xfe are considered 'true' in >> most contexts. >> >> >> > > that is how Bools operate, > > 0 = False, any other value is true... > > Compilers may use what ever value they wish to set a > bool to TRUE, but for better background control, the value > 1 is usually the value used when directly assigning a bool. No, they cannot. 1 is the only valid "true" value that can be assigned to a bool (or _Bool in C). If you write "bool b = 23;", the compiler /must/ assign 1 to b (or act as though it assigned 1 to it - optimisations may let it do something else as long as the effect of the program is as though it assigned 1 to b). This is the key difference between a "bool" (_Bool) and just using a uint8_t or char to store your flags. > > Maybe Type casting your variable to a BYTE, and doing the > bitwise operations will yield the results you are looking for. As I heard recently, "type casting" is what happens to film stars - "casting" is what you do in C. But no, casting your bool to a byte (uint8_t) will not help. The compiler knows the possible values of the bool (0 or 1), and thus knows the possible values the uint8_t will have after the cast (0 or 1). > > Back in the day, we used to use return values for both bools and > value. If the return was false than it's false, otherwise if it's true > then the same value is also used for some sort of condition information. > That is a completely different matter. A conditional statement ("if", "while", etc.) compares its argument to 0 (in C) or "contextually converts to bool" (in C++) - thus any non-false value is considered "true".