Re: [dwm] ntags initialization

From: Anselm R. Garbe <arg_AT_suckless.org>
Date: Fri, 5 Oct 2007 23:33:44 +0200

On Thu, Oct 04, 2007 at 08:17:51AM +0100, ste.buffaishere_AT_tin.it wrote:
> feature by looking at the dwm code when I found:
>
> for
> (ntags = 0; tags[ntags]; ntags++);
>
> which, I suppose, is used to
> initialize the `ntags' variable. However this point is not clear to me
> since
> `tags' is statically defined, then it would be possible to
> compute statically `ntags' as
>
> ntags = sizeof tags / sizeof tags[0] -
> 1;

That's true, but an evolutionary artefact ;) I'm going to
replace this with the sizeof calculation, but with the exception
to also remove the NULL array-terminator. This makes the -1
calculation obsolete.

 BE CAREFUL with the tags definition beginning with dwm 4.6,
 NULL won't be allowed anymore!!!

> and, as a side effect, knowing statically `ntags' allows to define
> `seltags' as an array without using
> `emallocz()'.
> What I am missing?

You miss that seltags and Client->tags are both globally defined
in the same context as the tags definition. Afaik you can't
evaluate the sizeof operator and you can't perform a division
operation in a non-functional scope, so I don't see how you
would like to replace the allocation of seltags and Client->tags
using emallocz.

Regards,

-- 
 Anselm R. Garbe >< http://www.suckless.org/ >< GPG key: 0D73F361
Received on Fri Oct 05 2007 - 23:33:44 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 14:57:41 UTC