[sdiy] Quick C query

Ben Lincoln blincoln at eventualdecline.com
Sun Nov 21 20:47:32 CET 2010


On 11/21/2010 10:38 AM, cheater cheater wrote:
> if(flags&  (A | B))
>
> is different from
>
> if(flags&  (A | B) == (A | B))
>
> in that the first will be active when either A or B are set in flags,
> whereas the second will trigger only when A and B are set in the
> flags.

This is one of the main reasons I avoid "programming shorthand". It 
takes a little longer to type out the full statement, but I'm a lot less 
likely to end up with something that behaves subtly differently than 
what I expect, and it's a lot easier to determine my original intent if 
I'm looking at the code again after a long time.

FWIW, I'm not a professional developer either, but I've coded in a lot 
of languages over the years, and when I use flag arrays, I tend to use 
this method rather than a struct (although in higher-level languages 
like C#, I would use a struct or class with boolean values because it's 
easier to read IMO).

On the subject of this type of hardware, is hand-tuned assembly still 
necessary these days? I know in the world of general-purpose PC 
hardware, the threshold was passed long ago, and it's generally 
considered not worth the trade-off in terms of the code becoming less 
-portable and less-maintainable by non-specialists (as well as the 
compiler being able to out-perform human optimization in most cases). 
I'm not familiar enough with embedded/programmable hardware to have an 
informed understanding of that side of things, though.

Obviously even if it's not strictly necessary, there's nothing wrong 
with enthusiasts doing it to squeeze the last possible drop of 
performance out of the hardware (which e.g. demo scene coders still do 
in the PC world).



More information about the Synth-diy mailing list