Re: Strange code in include/linux/cpumask.h

From: Rusty Russell
Date: Wed Mar 25 2009 - 18:46:19 EST


On Wednesday 25 March 2009 17:14:30 Nikanth Karthikesan wrote:
> On Wednesday 25 March 2009 10:41:11 Rusty Russell wrote:
> > Yes, except that this insists that bitmap be an unsigned long * or you'll
> > get a warning. Otherwise the macro could be used on anything. And it
> > needs to be a macro to use it as a static initializer.
>
> Ah, got it. Thanks a lot for the explanation. May be a comment could be added
> to the source.

Well, it's not that unusual a trick in the kernel, but an explanation might
help.

> Also looks like, this is not being used as a static initializer anywhere.
> i.e., Using my type-checking only version didn't trigger any error/warnings!

It will. cpu_all_mask uses to_cpumask, and it's replacing CPU_MASK_ALL.

> Being a deprecated interface, no new users are expected? Or is gcc smart, not
> complaining when used as static initializer, as it would always evaluate to
> (struct cpumask *)(bitmap)?

Yes, it seems to be. AFAICT though, using a function in an initializer is not
valid C.

> Can the sizeof constification be removed?

Possibly, but it makes me nervous to rely on it.

Thanks,
Rusty.


>
> Thanks
> Nikanth
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/