[Spice-devel] [spice-common 01/14] quic: Use #define rather than static const int

Christophe Fergeau cfergeau at redhat.com
Thu Jul 20 10:53:07 UTC 2017


On Tue, Jul 18, 2017 at 01:16:58PM -0400, Frediano Ziglio wrote:
> > 
> > On Wed, Jul 05, 2017 at 06:59:46AM -0400, Frediano Ziglio wrote:
> > > In my stash pile I have these:
> > > 
> > > 
> > > diff --git a/common/quic.c b/common/quic.c
> > > index c188ed2..aa0d8ab 100644
> > > --- a/common/quic.c
> > > +++ b/common/quic.c
> > > @@ -173,13 +173,13 @@ struct Encoder {
> > >  };
> > >  
> > >  /* target wait mask index */
> > > -static const int wmimax = DEFwmimax;
> > > +enum { wmimax = DEFwmimax };
> > >  
> > >  /* number of symbols to encode before increasing wait mask index */
> > > -static const int wminext = DEFwminext;
> > > +enum { wminext = DEFwminext };
> > >  
> > >  /* model evolution mode */
> > > -static const int evol = DEFevol;
> > > +enum { evol_mode_1 = 1, evol_mode_3 = 3, evol_mode_5  = 5, evol = DEFevol
> > > };
> > >  
> > >  /* bppmask[i] contains i ones as lsb-s */
> > >  static const unsigned long int bppmask[33] = {
> > > 
> > > 
> > > Seems to work and enums are compile time constants.
> > 
> > Did not answer to that one, but a #define for constants is more common than
> > using
> > enums this way. I'd be fine with
> 
> Is more used than you think. One reason is to add debug informations
> (preprocessor is just a string replacement in the source while enums
> carry information to the object level), the other is to avoid to clutter
> preprocessor and avoid preprocessor sides effects.
> Actually lot of system headers moved to enums using capital letters
> to retain the old look and feel.
> 
> > enum { evol_mode_1 = 1, evol_mode_3 = 3, evol_mode_5  = 5 };
> 
> Won't work to solve the evol "issue".

Maybe not, all I'm saying is that I see your suggestion as an abuse of
enums, and I'd rather not do that to workaround to what I would call a
compiler issue. We are not going to debug that piece of code very often,
and the constants are not used a lot, so we should be fine with #define.

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20170720/b33c3537/attachment.sig>


More information about the Spice-devel mailing list