
Zitat von
alcaeus:
Du musst nicht OR verwenden, du kannst sie ganz einfach addieren:
Diese Konstanten sind ja immer 2^n.
Das sind sie nicht immer. Zudem gibt es dann Probleme mit Alias-Konstanten...
Keine Gute Idee:
Delphi-Quellcode:
const
Foo = 1;
Bar = 2;
All = Foo or Bar;
...
Bug := All + Foo;
Die sicherste Variante:
Delphi-Quellcode:
NoBug := All or Foo;
...
if (NoBug and Foo) = Foo then
Alles andere sind Optimierungen für die Falle, dass die Konstanten a) keine gemeinesamen Bits und b) jeweils nur ein Bit gesetzt haben (und man weiss was man tut

).
Gruss Nico
ps: 'or' und 'and' gehören zu einer andere Algebra und haben nichts mit + und - zu tun.