[Ffmpeg-devel] [PATCH] video4linux2 input

Måns Rullgård mru
Tue Feb 7 12:15:47 CET 2006


Erik Slagter said:
> On Mon, 2006-02-06 at 17:14 +0000, M?ns Rullg?rd wrote:
>> >> To be even more elegant, I'd use a enum AND a table. #define's for
>> >> constants are evil, indeed.
>> >
>> > Do you have any good reason to say this or is it just more CS dogma?
>>
>> The one good thing with enums is that debugger can show the symbolic names.
>> Apart from that, they are semantically equivalent to ints IIRC,
>
> Almost IIRC ;-)

Here's what the ISO C99 standard has to say:

  The identifiers in an enumerator list are declared as constants that
  have type int and may appear wherever such are permitted. 107) An
  enumerator with = defines its enumeration constant as the value of
  the constant expression. If the first enumerator has no =, the value
  of its enumeration constant is 0. Each subsequent enumerator with no
  = defines its enumeration constant as the value of the constant
  expression obtained by adding 1 to the value of the previous
  enumeration constant. (The use of enumerators with = may produce
  enumeration constants with values that duplicate other values in the
  same enumeration.) The enumerators of an enumeration are also known
  as its members.

  107) Thus, the identifiers of enumeration constants declared in the
  same scope shall all be distinct from each other and from other
  identifiers declared in ordinary declarators.

>> with the
>> addition of polluting the namespace.  I rarely use them (or debuggers).
>
> Huh? How do you mean a #define does not pollute namespace? I'd rather
> say that a define pollutes name space. If you're using _anything_ with
> the same name in the same (or included!) file it will cause really
> obscure errors!

#define operates in the preprocessor namespace, which is distinct from the
C compiler namespace.  Sure, #defined names are global, but at least they
give some additional value, such as the ability to use #ifdef.  There's
also #undef, so it's possible to clean up the namespace when you no longer
need a particular macro.

-- 
M?ns Rullg?rd
mru at inprovide.com





More information about the ffmpeg-devel mailing list