Hi,
I have started a discussion in comp.lang.c which deals with this
problem. Keith Thomson has rewritten the demo program (see below).
output of debuggable executable:
null_pointer = 0
sizeof(void *) = 4
sizeof(test_t *) = 4
sizeof(int *) = 4
p = a20060
p->next = 101f1efd
p->prev = 101f1efd
p->status = 0
p->condnr = 101f1efd
output of release executeable:
null_pointer = 0
sizeof(void *) = 4
sizeof(test_t *) = 4
sizeof(int *) = 4
p = a20060
p->next = 0
p->prev = 0
p->status = 0
p->condnr = 0
This means that the debuggable executable has some problem.
Franz Hollerer
1 #include
2 #include
3 #include
4
5 /*
6 * I've deleted the superfluous declaration for memalloc. -- kst
7 */
8
9 void *memalloc(size_t size)
10 /*
11 * Old-style declarations are still legal, but there's really
12 * no point in using them. -- kst
13 */
14 {
15 void *p;
16
17 p=malloc(size);
18
19 if (!p)
20 {
21 fprintf(stderr, "malloc() faild\n");
22 exit(1);
23 }
24
25 memset(p, 0, size);
26 /*
27 * As others have pointed out, this sets the struct to all zeros,
28 * so it doesn't necessarily set the next, prev, and condnr
members
29 * to NULL. I don't think that's causing the problem you're
seeing,
30 * though. -- kst
31 */
32
33 return(p);
34 }
35
36 /* =============================================== */
37
38 typedef struct condgen_t{
39 int *next, *prev;
40 int status;
41 int *condnr;
42 } test_t;
43
44 /*
45 * Added function show_info() to show some possibly relevant
46 * characteristics of your system.
47 */
48 void show_info(void)
49 {
50 void *null_pointer = NULL;
51
52 printf("null_pointer = %p\n", null_pointer);
53 printf("sizeof(void*) = %d\n", (int)sizeof(void*));
54 printf("sizeof(test_t*) = %d\n", (int)sizeof(test_t*));
55 printf("sizeof(int*) = %d\n", (int)sizeof(int*));
56 }
57
58 int main(void)
59 /*
60 * Changed declaration from "int main()" to "int main(void)" -- kst
61 */
62 {
63 test_t *p;
64 p = memalloc(sizeof(test_t));
65 /*
66 * Deleted unnecessary void* intermediate pointer. memalloc()
67 * returns a void*, but you can assign the result directly to
68 * a test_t*. -- kst
69 */
70 show_info();
71 printf("p = %p\n", (void*)p);
72 printf("p->next = %p\n", (void*)p->next);
73 printf("p->prev = %p\n", (void*)p->prev);
74 printf("p->status = %d\n", p->status);
75 printf("p->condnr = %p\n", p->condnr);
76 /*
77 * Finally, show some information. -- kst
78 */
79 getchar();
80 return 0;
81 /*
82 * Note: The "return 0" isn't just to avoid a gcc warning, it's
83 * a necessary part of the program. Without it, you'd be
returning
84 * some arbitrary status to the environment. -- kst
85 */
86 }
87
--
Institut fuer Hochenegiephysik
Nikolsdorfer Gasse 18
1050 Wien
Austria
Tel: (+43-1)5447328/50