[sdiy] Quick C query

Steff steff at steff.name
Sun Nov 21 17:41:01 CET 2010

On 21 November 2010 13:31, Tom Wiltshire <tom at electricdruid.net> wrote:
> Hi there,
> Not directly synth-related, but I'm learning C in order to write code for my synth's main processor board!
> What's the best way to deal with booleans in C? I see that we don't have a Boolean type explicitly.
> Presumably there's a standard practice for this, since I'm not the first person to need a boolean.
> If it makes any odds, I'm using Microchip's C Lite on dsPIC.

If your specific compiler implements C99, you should find there's a
header stdbool.h which introduces a type "bool". It's just an int
really, though, so bitfields may make more sense if memory's tight.

Traditionally, one sees quite of a lot of this sort of thing:

[in a header file somewhere]
#define FOO 1
#define BAR 2
#define BAZ 4
#define BLARP 8

followed by:

[in code somewhere]
if(flags == (BLARP | BAR)) { /* do stuff here */ }



Disclaimer: I'm a sysadmin who occasionally has to read or write C,
not a C language scientist.

More information about the Synth-diy mailing list