Query about running a program through valgrind and getting false results comparing to other systems.

Posted by FILIaS on Stack Overflow See other posts from Stack Overflow or by FILIaS
Published on 2011-01-11T18:43:33Z Indexed on 2011/01/11 18:53 UTC
Read the original article Hit count: 218

Filed under:

Yesterday i posted this: What's the problem with this code? [hashtable in C] and paxdiablo offered to help me. He posted a sample of code and asked me to run it through valgrind on my machine. This code normally generates: 12,4 But on my machine, i get 24,8. The doubled! I'm just curious why is that happening. Hope sb has a good explaination.

I post also paxdiablo's code (for anyone who cant find it.)

#include <stdio.h>
#include <stdlib.h>

typedef struct HashTable {
    int size ;
    struct List *head;
    struct List *tail;
} HashTable;

typedef struct List {
    char *number;
    char *name;
    int time;
    struct List *next;
} List;

#define size_of_table 211

HashTable *createHashTable(void) {
    HashTable *new_table = malloc(sizeof(*new_table)*size_of_table); //line 606
    printf ("%d\n", sizeof(*new_table));
    printf ("%d\n", sizeof(new_table));
    if (new_table == NULL) {
        return NULL;
    }

    int i=0;
    for(i; i<size_of_table; i++) {
        new_table[i].size=0;
        new_table[i].head=NULL;
        new_table[i].tail=NULL;
    }
    return new_table;
}

int main(void) {
    HashTable *x = createHashTable();
    free (x);
    return 0;
}

© Stack Overflow or respective owner

Related posts about c