[pacman-dev] [PATCH 3/3] Align titles automatically in information display

Dave Reisner d at falconindy.com
Sat Oct 17 15:54:40 UTC 2015


On Sat, Oct 17, 2015 at 05:44:20PM +0200, Pierre Neidhardt wrote:
> Thanks for all the good tips!
> 
> On 15-10-17 09:11:02, Dave Reisner wrote:
> > Nit: it'd be more clear to use TITLE_ as a prefix instead of T_.
> 
> These constants are used to index the 'titles' variable. Having a TITLE prefix
> would make it look like
> 
> 	titles[TITLE_DESCRIPTION]
> 
> which I find a bit redundant. It also avoids potential future clashes with
> TITLE_MAXLEN and TITLE_COUNT. (I removed the other TITLE_* variables as you
> suggested.)

Well, but any clashes are easily resolved. They'd be compile time errors
as the resulting code would look something like:

  enum {
    TITLE_FOO,
    TITLE_BAR,
    42,
    TITLE_BAZ,
  };

Since the preprocessed token is no longer an identifier, the compiler
whines.

> > > +	/* make aligned titles once only */
> > > +	static int need_alignment = 1;
> > > +	if(need_alignment) {
> > > +		need_alignment = 0;
> > > +		make_aligned_titles();
> > > +	}
> >
> > Why not just have make_aligned_titles() return a dummy int value? Then,
> > you can:
> >
> >   static const int make_aligned_once = make_aligned_titles();
> 
> I don't think this would work: static variables are initialized at compile time
> if I'm not mistaken.

Ah right, this only works in C++.

> --
> Pierre Neidhardt


More information about the pacman-dev mailing list