I have some code that I need to duplicate for several structs, and I don't want to manually copy/paste, then search and replace the words.

I have a container object, a struct scene, which holds arrays of triangles, spheres and quadrilaterals.
Code:
scene.triangles
And it keeps count of how many triangles there are like this:
Code:
scene.triangleCount
Now you could replace triangle with sphere or quad.
I have a function that removes a triangle or a sphere or a quad from a scene. It does this by finding the index of the array associated with the provided pointer, then moving the last item in that array to the index, then freeing the pointer, then finally decrementing the count.

You can search/replace "@TYPE@" for "triangle", "quad", "sphere". Is there a compiler macro or a pragma which does this automatically so I don't have to copy/paste?

Code:
static inline void remove@TYPE@(struct scene * scene, struct @TYPE@ * object){
    lockScene(scene); // multiprocessing concerns
    for (unsigned int i = 0; i < scene->@TYPE@Count; ++i){
        if (scene->@TYPE@s[i] == object){

            scene->@TYPE@s[i] = scene->@TYPE@s[scene->@TYPE@Count-1];
            scene->@TYPE@s[scene->@TYPE@Count-1] = NULL;
            scene->@TYPE@Count--;

            unlockScene(scene); // multip again

            free(object->mat);
            free(object);
            return;
        }
    }

    assert(1==0); // if we ended up here we failed to find it, crash program
}