Programming Thread

Viewing single post

Started by the-pi-guy, Mar 13, 2016, 10:39 PM

previous topic - next topic

darkknightkryta

Dec 16, 2017, 06:56 PM Last Edit: Dec 16, 2017, 06:59 PM by darkknightkryta
I think it's possible to have a pointer variable, that points to a function.  
Never tried it, but I recall reading something about it.  

I've been messing around some more.  

For some reason, this method is changing the value.  literally one line:
Code: [Select]

int getSize(int i)
return list[i].size;

Yes you can make a variable point to a function.  I vaguely recall it being in a lab.  Not sure why'd you would use it.

So what the assignment is, is to implement malloc (memory allocation).
But it requires a data structure to keep track of data locations.  

I was using an array that would change length, by getting reassigned basically.  

But apparently assigning the arrays that way has some unusual behaviors.  

I changed all the declarations to utilizing malloc, which feels wrong.  Now it works great.  

It's apparently fine if the data structure uses malloc, but eh I don't like it.  
Memory related issues are the hardest to debug.  C's memory system isn't that good either (Was at the time I guess).  Though as I tell all my students "Be kind to C and C will be kind to you"  So use malloc and like it :P