On Wednesday 05 February 2003 6:18 pm, Tim Hockin wrote:
That is a
great feature of C++ but PortAudio is using 'C' not C++. So I
think our only choices are #define and enum. PortAudio uses both.
you can still use const variables - gcc with optimizations treats them like
defines, but with type-safety.
Consts are slightly different in standard C, though - they are treated as
ordinary variables that can't be changed. This means that in some non-gcc
compilers you can't say
const int a=10;
/* ... */
int n[a];
like you can in C++ or gcc without the --pedantic option. That's why you'll
often see enums used to specify array bounds in portable code.
> Are enums better than #defines?? I am always
trying to improve my 'C'
> chops so I am open to suggestions.
only in that macros are generally a Bad Thing.
++templates_are_cool;, by the way ;)
If you can enumerate the values, you should, IMHO. Of
course, there are
times to break this, but in general YES. An enum is a real type, and can
be used as such.
enum foo_cmd {
FOO_A,
FOO_B,
FOO_C,
};
int doo_foo_cmd(enum foo_cmd cmd);
Tim