I have also created the UDF in the database by running the following CREATE FUNCTION SQL statement:
REPLACE FUNCTION DP_UTIL.MAXDATE(indate TIMESTAMP(6)) RETURNS TIMESTAMP(6) LANGUAGE C NO SQL PARAMETER STYLE TD_GENERAL EXTERNAL NAME 'CI!maxdate!M:\DBA\Function\maxdate\maxdate.h!CS!maxdate!M:\DBA\Function\maxdate\maxdate.c!F!maxdate';
COMMENT ON FUNCTION DP_UTIL.MAXDATE IS 'Function to replace its TIMESTAMP argument with MAXDATE if it is greater or equal to the THRESHOLDDATE';
When I SELECT FROM DBC.Functions I can see the function has been created correctly (with correct arguments). When I try to call the function, though, I am getting the 7502 error ("A system trap was caused by UDF/XSP/UDM DP_UTIL_MAXDATE for SIGSEGV"). So the function basically crashes.
You need to look at the documentation for writing UDFs again. The C prototype is not correct. The UDF C code never returns anything via the C return parameter. It is always defined as returns void. What happens is that the stack frame is not generated correctly. That is why you got the trap. Also note that the definition of DECIMAL4 is an int in (8,6) decimal format. This means you have to multiply the seconds by 1000000 to move the decimal point over in the implied decimal point of the int. Try this correct example. It should work for you:
#define SQL_TEXT Latin_Text #include
/* create statement :
replace function maxdate(timestamp(6)) returns timestamp(6) language C no SQL PARAMETER STYLE TD_GENERAL external;