Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.arch.embedded > #25008
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | comp.arch.embedded |
| Subject | Re: XC8 novice question |
| Date | 2016-09-12 09:00 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <nr5jpp$4e1$1@dont-email.me> (permalink) |
| References | (2 earlier) <lsWdnZAlF6m2rEjKnZ2dnUU7-bmdnZ2d@westnet.com.au> <nr3fhp$lj$1@dont-email.me> <nr3pu9$2ro$1@dont-email.me> <EofBz.519583$tK.358369@fx36.am4> <KufBz.519584$tK.510392@fx36.am4> |
On 11/09/16 18:19, Tom Gardner wrote:
> On 11/09/16 17:13, Tom Gardner wrote:
>> On 11/09/16 15:32, Don Y wrote:
>>> On 9/11/2016 4:35 AM, David Brown wrote:
>>>> Also consider:
>>>> static const uint8_t my_variable = 0b10000000;
>>>>
>>>> instead of the #define, unless you really need it to be a #define'd
>>>> value (such
>>>> as to give the size of an array, or because you have a crap compiler).
>>>
>>> A drawback to this approach is it allows the OP to continue to think
>>> of it as a "variable". Either rename it ("my_constant" or
>>> "MY_CONSTANT")
>>> or use a manifest constant so each reference is ACTUALLY replaced with
>>> the PREPROCESSOR SUBSTITUTION:
>>> MY_CONSTANT = 7; (wrong!)
>>> becomes:
>>> 128 = 7;
>>> (which is CLEARLY wrong!)
>>>
>>> [Time for bed...]
>>
>> Except, of course, that 0b10000000 == 512, which is probably the
>> source of the original "warning: (752) conversion to shorter
>> data type"
>
> Oops. Please ignore my dyslexia, or maybe my eyesight is going.
>
Actually, you raise a good point - 0b10000000 is hard to read. 0b
constants are fine for small values, and okay for bigger values if there
are plenty of 0's and 1's. But your eyes need a transition every 4 or 5
digits for clock recovery. So numbers like this are often better
expressed as hex (0x80), or with shifts (1u << 7) or perhaps (0b1000 <<
4), if that suits a pattern with other defined constants in the code.
Or use C++14, and write 0b1000'0000. (The ' separator the C++ standards
folks picked may not be the nicest choice, but it is better than nothing.)
Back to comp.arch.embedded | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
XC8 novice question rwood <rwoodl@nowhere.com> - 2016-09-11 15:02 +0800
Re: XC8 novice question Don Y <blockedofcourse@foo.invalid> - 2016-09-11 02:55 -0700
Re: XC8 novice question rwood <rwoodl@nowhere.com> - 2016-09-11 18:25 +0800
Re: XC8 novice question David Brown <david.brown@hesbynett.no> - 2016-09-11 13:35 +0200
Re: XC8 novice question Don Y <blockedofcourse@foo.invalid> - 2016-09-11 07:32 -0700
Re: XC8 novice question David Brown <david.brown@hesbynett.no> - 2016-09-11 16:58 +0200
Re: XC8 novice question Don Y <blockedofcourse@foo.invalid> - 2016-09-11 13:15 -0700
Re: XC8 novice question David Brown <david.brown@hesbynett.no> - 2016-09-12 08:55 +0200
Re: XC8 novice question Don Y <blockedofcourse@foo.invalid> - 2016-09-12 02:41 -0700
Re: XC8 novice question Mike Perkins <spam@spam.com> - 2016-09-12 13:16 +0100
Re: XC8 novice question David Brown <david.brown@hesbynett.no> - 2016-09-12 14:56 +0200
Re: XC8 novice question Mike Perkins <spam@spam.com> - 2016-09-12 14:33 +0100
Re: XC8 novice question David Brown <david.brown@hesbynett.no> - 2016-09-12 16:11 +0200
Re: XC8 novice question Jack <jack4747@gmail.com> - 2016-09-12 07:50 -0700
Re: XC8 novice question David Brown <david.brown@hesbynett.no> - 2016-09-12 22:23 +0200
Re: XC8 novice question Les Cargill <lcargill99@comcast.com> - 2016-09-12 15:34 -0500
Re: XC8 novice question Don Y <blockedofcourse@foo.invalid> - 2016-09-12 08:44 -0700
Re: XC8 novice question David Brown <david.brown@hesbynett.no> - 2016-09-12 14:35 +0200
Re: XC8 novice question Don Y <blockedofcourse@foo.invalid> - 2016-09-12 08:19 -0700
Re: XC8 novice question David Brown <david.brown@hesbynett.no> - 2016-09-12 23:11 +0200
Re: XC8 novice question Dennis <dennis@none.none> - 2016-09-12 17:04 -0500
Re: XC8 novice question Don Y <blockedofcourse@foo.invalid> - 2016-09-12 22:49 -0700
Re: XC8 novice question David Brown <david.brown@hesbynett.no> - 2016-09-13 09:04 +0200
Re: XC8 novice question Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2016-09-13 00:16 +0200
Re: XC8 novice question Don Y <blockedofcourse@foo.invalid> - 2016-09-12 21:22 -0700
Re: XC8 novice question David Brown <david.brown@hesbynett.no> - 2016-09-13 12:25 +0200
Re: XC8 novice question Dennis <dennis@none.none> - 2016-09-13 10:22 -0500
Re: XC8 novice question David Brown <david.brown@hesbynett.no> - 2016-09-13 20:08 +0200
Re: XC8 novice question rwood <rwoodl@nowhere.com> - 2016-09-12 16:50 +0800
Re: XC8 novice question Tom Gardner <spamjunk@blueyonder.co.uk> - 2016-09-11 17:13 +0100
Re: XC8 novice question Tom Gardner <spamjunk@blueyonder.co.uk> - 2016-09-11 17:19 +0100
Re: XC8 novice question David Brown <david.brown@hesbynett.no> - 2016-09-12 09:00 +0200
Re: XC8 novice question Don Y <blockedofcourse@foo.invalid> - 2016-09-11 07:28 -0700
Re: XC8 novice question upsidedown@downunder.com - 2016-09-11 13:56 +0300
Re: XC8 novice question David Brown <david.brown@hesbynett.no> - 2016-09-11 13:28 +0200
Re: XC8 novice question Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2016-09-11 13:36 +0200
Re: XC8 novice question upsidedown@downunder.com - 2016-09-11 16:14 +0300
Re: XC8 novice question Don Y <blockedofcourse@foo.invalid> - 2016-09-11 07:57 -0700
Re: XC8 novice question Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2016-09-12 22:52 +0200
Re: XC8 novice question upsidedown@downunder.com - 2016-09-13 10:11 +0300
Re: XC8 novice question Don Y <blockedofcourse@foo.invalid> - 2016-09-13 01:11 -0700
Re: XC8 novice question upsidedown@downunder.com - 2016-09-13 13:24 +0300
Re: XC8 novice question David Brown <david.brown@hesbynett.no> - 2016-09-13 12:39 +0200
Re: XC8 novice question Don Y <blockedofcourse@foo.invalid> - 2016-09-13 15:41 -0700
Re: XC8 novice question upsidedown@downunder.com - 2016-09-14 09:07 +0300
Re: XC8 novice question Don Y <blockedofcourse@foo.invalid> - 2016-09-13 23:29 -0700
Re: XC8 novice question Don Y <blockedofcourse@foo.invalid> - 2016-09-11 07:50 -0700
Re: XC8 novice question Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2016-09-11 13:42 +0200
Re: XC8 novice question Tim Wescott <tim@seemywebsite.com> - 2016-09-11 20:14 -0500
Re: XC8 novice question rwood <rwoodl@nowhere.com> - 2016-09-12 16:54 +0800
Re: XC8 novice question David Brown <david.brown@hesbynett.no> - 2016-09-12 11:05 +0200
Re: XC8 novice question rwood <rwoodl@nowhere.com> - 2016-09-12 18:48 +0800
Re: XC8 novice question John Temples <usenet@xargs-spam.com> - 2016-09-12 17:33 +0000
csiph-web