Messages in this thread | | | Date | Tue, 30 Sep 2008 09:46:59 -0700 (PDT) | From | Linus Torvalds <> | Subject | Re: [Bug #11342] Linux 2.6.27-rc3: kernel BUG at mm/vmalloc.c - bisected |
| |
On Tue, 30 Sep 2008, Mike Travis wrote: > > One pain is: > > typedef struct __cpumask_s *cpumask_t; > const cpumask_t xxx; > > is not the same as: > > typedef const struct __cpumask_s *const_cpumask_t; > const_cpumask_t xxx; > > and I'm not exactly sure why.
Umm. The const has different
One is
typedef const struct __cpumask_s *const_cpumask_t;
which becomes
(const struct __cpumask_s) *
while the other is
const cpumask_t xxx
which is
const (struct __cpumask_s *)
and if you look a bit more closely, you'll see that they are _obviously_ not the same thing at all.
Quite frankly, I personally do hate typedefs that end up being pointers, and used as pointers, without showing that in the source code.
When you do
type_t a;
fn(a);
I expect the code to essentially do a pass-by-value. But when the type_t is a pointer, that doesn't really work.
Your issue with 'const' is just another version of the same. You don't want the _pointer_ to be const, you want what it points _to_ to be const. But because you hid the pointerness inside the typedef, you simply cannot do that.
The problem with cpumask's, of course, is that for the "small mask" case, we really don't want it to be a pointer. So now it's sometimes a pointer and sometimes not. The typedef hides that, and I understand why it's a good idea, but I'm surprised you didn't understand what the implications were for 'const', and I'm now a bit more leery about this whole thing just because the typedef ends up hiding so much - it doesn't just hide the basic type, it hides a very basic *code* issue.
Linus
| |