You can define a single "constructor" that takes a void * initialization parameter and an enum:
enum StringCtor { SC_DEFAULT, SC_C_STR, SC_COPY }; String new_String(enum StringCtor type, const void *arg); String s1 = new_String(SC_DEFAULT, 0); String s2 = new_String(SC_C_STR, "hello"); String s3 = new_String(SC_COPY, &s2);
You could also choose to use a ... instead of a void *. The idea is the same, but you use the va_* macros to extract the parameter if it supposed to be a string or a copy.
If you just want the API to have the appearance of a single constructor, but still want type safety, you can use the techniques above to create your actual constructor implementation, and use inline functions and preprocessor tricks to give the appearance of a single constructor, with type safety.
String new_StringImpl(enum StringCtor type, const void *arg); static inline String new_StringImplDefault () { return new_StringImpl(SC_DEFAULT, 0); } static inline String new_StringImplCstr (const char *s) { return new_StringImpl(SC_C_STR, s); } static inline String new_StringImplCopy (String *s) { return new_StringImpl(SC_COPY, s); } #define new_String_Paste(TYPE) new_String_ ## TYPE #define new_String_SC_DEFAULT(ARG) new_StringImplDefault() #define new_String_SC_C_STR(ARG) new_StringImplCstr(ARG) #define new_String_SC_COPY(ARG) new_StringImplCopy(ARG) #define new_String(TYPE, ...) new_String_Paste(TYPE)(__VA_ARGS__) String s1 = new_String(SC_DEFAULT); String s2 = new_String(SC_C_STR, "hello"); String s3 = new_String(SC_COPY, &s2);
Notice with the variadic macro, SC_DEFAULT does not need a second parameter any more. At sufficient optimization levels, the code translates to just a call to the single implementation function, with the benefit of compile time type safety checks. So at the cost of some more coding on your part, you can give the user of your library the appearance of a single constructor API with all the type safety of multiple constructor functions.
gtk_icon_view_convert_widget_to_bin_window_coords().