Re: [PATCH 2.6.17-rc6 7/9] Remove some of the kmemleak false positives
From: Catalin Marinas
Date: Mon Jul 24 2006 - 09:26:03 EST
On 24/07/06, Ingo Molnar <mingo@xxxxxxx> wrote:
update: there's also a neat gcc extension trick suggested by Arjan:
__builtin_classify_type(). This converts types into integers!
It's not really reliable as it doesn't distinguish well between types.
All the structures, no matter what they contain, have the same id
(which I think only refers to the fact that it is built-in type,
pointer or structure, without differentiation).
The attached code gives the following results:
typeof(a) = 12, sizeof(a) = 136
typeof(b) = 12, sizeof(b) = 8
typeof(c) = 1, sizeof(c) = 4
typeof(d) = 1, sizeof(d) = 4
typeof(e) = 1, sizeof(e) = 4
typeof(f) = 1, sizeof(f) = 1
typeof(g) = 5, sizeof(g) = 4
typeof(h) = 5, sizeof(h) = 4
--
Catalin
#include <stdio.h>
struct A {
void *a;
long b;
char c[128];
};
struct B {
long a;
void *b;
};
enum C {
a,
b
};
#define PRINT_TYPE(val) \
printf("typeof(" #val ") = %d, sizeof(" #val ") = %d\n", \
__builtin_classify_type(val), \
sizeof(val))
int main()
{
struct A a;
struct B b;
enum C c;
int d;
long e;
char f;
int *g;
char *h;
PRINT_TYPE(a);
PRINT_TYPE(b);
PRINT_TYPE(c);
PRINT_TYPE(d);
PRINT_TYPE(e);
PRINT_TYPE(f);
PRINT_TYPE(g);
PRINT_TYPE(h);
return 0;
}