I'm looking into vectors in C, i.e. dynamically resizable arrays. I've implemented one that handles a char array.

But if I want the same functionality for a different type of array -- int, long etc- I'd have to do the whole thing over, as well as use different names for them not to collude given that they'd be in the same namespace.

My question is: is there any way to handle either an int array or a char array depending on a certain argument passed to the intializer function?

So say I have a struct Vector with a member that's a char pointer. As it stands, when I run the init function, it'll allocate memory to this char pointer for use as a char array.

Can I make it so that, depending on a certain argument passed to init, it will allocate memory for an int array instead of a char array, for example?

I've been thinking about this and it would involve using void pointers and casting in a bunch of places. Is there any other way/what's the best way to go about this?