C header to Pascal , what is the type of ENUM?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

C header to Pascal , what is the type of ENUM?

Dennis
In C
ENUM_BEGIN( RetCode )
     /*      0 */  ENUM_DEFINE( TA_SUCCESS, Success ), /* No error */
     /*      1 */  ENUM_DEFINE( TA_LIB_NOT_INITIALIZE, LibNotInitialize
), /* TA_Initialize was not sucessfully called */
     /*      2 */  ENUM_DEFINE( TA_BAD_PARAM, BadParam ), /* A parameter
is out of range */
     /*      3 */  ENUM_DEFINE( TA_ALLOC_ERR, AllocErr ), /* Possibly
out-of-memory */
     /*      4 */  ENUM_DEFINE( TA_GROUP_NOT_FOUND, GroupNotFound ),
     /*      5 */  ENUM_DEFINE( TA_FUNC_NOT_FOUND, FuncNotFound ),
     /*      6 */  ENUM_DEFINE( TA_INVALID_HANDLE, InvalidHandle ),
     /*      7 */  ENUM_DEFINE( TA_INVALID_PARAM_HOLDER,
InvalidParamHolder ),
     /*      8 */  ENUM_DEFINE( TA_INVALID_PARAM_HOLDER_TYPE,
InvalidParamHolderType ),
     /*      9 */  ENUM_DEFINE( TA_INVALID_PARAM_FUNCTION,
InvalidParamFunction ),
     /*     10 */  ENUM_DEFINE( TA_INPUT_NOT_ALL_INITIALIZE,
InputNotAllInitialize ),
     /*     11 */  ENUM_DEFINE( TA_OUTPUT_NOT_ALL_INITIALIZE,
OutputNotAllInitialize ),
     /*     12 */  ENUM_DEFINE( TA_OUT_OF_RANGE_START_INDEX,
OutOfRangeStartIndex ),
     /*     13 */  ENUM_DEFINE( TA_OUT_OF_RANGE_END_INDEX,
OutOfRangeEndIndex ),
     /*     14 */  ENUM_DEFINE( TA_INVALID_LIST_TYPE, InvalidListType ),
     /*     15 */  ENUM_DEFINE( TA_BAD_OBJECT, BadObject ),
     /*     16 */  ENUM_DEFINE( TA_NOT_SUPPORTED, NotSupported ),
     /*   5000 */  ENUM_DEFINE( TA_INTERNAL_ERROR, InternalError ) = 5000,
     /* 0xFFFF */  ENUM_DEFINE( TA_UNKNOWN_ERR, UnknownErr ) = 0xFFFF
ENUM_END( RetCode )

The function in C is
TA_RetCode TA_EMA( int    startIdx,
                    int    endIdx,
                    const double inReal[],
                    int           optInTimePeriod, /* From 2 to 100000 */
                    int          *outBegIdx,
                    int          *outNBElement,
                    double        outReal[] );

my question is, what should the type of TA_RetCode be in Pascal? Word (2
byte) or LongWord (4 bytes)?

In short, is this pascal translation correct?
function TA_EMA(startIdx, endIdx : integer;
                    const inReal : PDouble;
                    optInTimePeriod : integer;
                    var utBegIdx,
                    outNBElement : integer;
                    outReal : PDouble ) : Word;stdcall; external
'ta_func.dll';

Note: the dll is 64-bit windows but I am not sure whether int should
translate to Integer or Int64 in Pascal.

Dennis
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: C header to Pascal , what is the type of ENUM?

Martok
Am 23.02.2018 um 16:06 schrieb Dennis:
> In C
> ENUM_BEGIN( RetCode )
TA-Lib has very weird macros. It should expand to "enum class RetCode" (so it's
actually C++), making this an int or unsigned int (depending on the compiler).
Should be a Longword on >32bit compilers then.

And (MvC will be disappointed if I wouldn't say it): don't translate as a Pascal
enum unless you know what you're doing.

--
Regards,
Martok

Ceterum censeo b32079 esse sanandam.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal