Weird malloc?

Aug 25, 2011 at 7:34 PM

At line 664 there is this allocation:

 hMods = (HMODULE*) malloc(sizeof(HMODULE) * (TTBUFLEN / sizeof HMODULE));

Just tried to compile it with gcc and it complained about the missing '()' around the last 'HMODULE'. 

The expression as it stands is "A * (X / A)". Which I learned in math-class is the same as "A". Why the complexity? 


Jun 13, 2013 at 2:14 PM
old post.. but if anyone will need an answer -
Since this is integer division A(X/A) != X
This was done so the allocated memory will always be divisible by sizeof(HMODULE).
So if sizeof(HMODULE) is 4, and TTBUFLEN is 9, the resulting allocated memory will still be 8=4
Sep 14, 2014 at 7:21 PM
sizeof syntax corrected in main trunk
Marked as answer by jkalmbach on 9/15/2014 at 2:03 AM