hi,
i'm really new to c, so this might be trivial, but i'll ask anyway.
i have to implement a simple malloc/free. due to some restrictions (the 'memory' is array of ints, no static variables (all the housekeeping inside the array itself)) i went for what seemed as the most obvious - my malloc now puts headers in front of the data, in the form of a couple of indexes to the array. the code looks awful with all those [i + 1 + smth] and similar indexes.
now i'm thinking if i could possibly make it prettier with structs? say, if i were given a pointer to an int (which would point to beginning of the header bit), can i cast it to struct header *, so that instead of having all those array indexes i could just say h.next, h.prev, h.size and so on? if so, could you show some code snippet? because i've been trying around, but i'm not quite sure what would be the right way. or, if you have any better ideas how to make my malloc better, please share them as well
thanks a lot