[QUOTE]\n[QUOTE="Robbie Brown"]\nOn 26/01/14 13:15, Ben Bacarisse wrote: [QUOTE]\nBy the way, you can reduce allocation size mistakes by using the\npattern:\n\nvar = malloc(sizeof *var * number_of_elements);[/QUOTE]\n\nI have valgrind working and it certainly indicates a problem ... but I\ndon't understand the above (duh!). I think someone else mentioned\nsomething like this before and I didn't get then either (duh! duh!)\n\nvar = malloc(sizeof *var * number_of_elements);[/QUOTE]\n\nThe idea is whatever is on the left is written with * in front on the\nright, so I'd have put sizeof *var there, myself.\n[QUOTE]\n1. I thought malloc returned a pointer[/QUOTE]\n\nYes. presumably in my example var is a pointer object. In yours,\nvar must be a pointer object. sizeof *var is the size of the type\nof object pointed to var var.\n[QUOTE]\n2. If I want an int (32 bits on this machine) why ask for a pointer to\nint (64 bits)[/QUOTE]\n\nI'm baffled! sizeof can be applied to an expression. It does not evaluate the\nexpression, it just looks to see what type it is and uses that type to\ndetermine the size. See below...\n[QUOTE]\nso\n\nint *i = malloc(sizeof(int));\nshould give me a 64 bit pointer to a 32 bit int[/QUOTE]\n\nBut int *i = malloc(sizeof *i); also works. i is of type 'int *' so *i\nis of type 'int'.\n[QUOTE]\nSorry for being so thick, can you elucidate please.[/QUOTE]\n\nNot knowing stuff is not at all the same as being thick. We all started\noff knowing no C at all.[/QUOTE]\n\nYou're very kind :-)\n\nAnyway, I'm pretty sure I see what you mean, I'll do some experimenting\ntomorrow, it's been a long day.\n\nBTW valgrind is a wicked bit of kit, cheers for the heads up.\n\nI was convinced my dynamically allocated LinkedList was working, and it\nwas but I hadn't got the freeing up of memory quite right, there was a\nsmall leak that I was able to fix and an unitialized variable that I\nhadn't caught. I would *never* have figured that out at my current level\nof knowledge without.