Defining Function Types in C
12:16 17 Apr 2026

I am trying to define a single function in C that can handle more than one input and return types. As part of this I would like the function to execute different code segments within the function itself based on the type value. The code below is my thoughts on how to possibly achieve this, but I'm not certain its the proper approach.

#define TVAL(type) (type)

TVAL(type) func1(TVAL(type) x,TVAL(type) y)
{
    TVAL(type) result;

    if (TVAL(type)=BYTE) {
        // code to execute for a BYTE type
    }
    if (TVAL(type)=WORD) {
        // code to execute for a WORD type
    }
    return(result);
}

I have looked for possible solutions and haven't located anything specific. If you have any sources about this or ideas related to this situation I'd be very open to learning more.

c