Q(uick)BASIC Keyword: CDECL

Quick View

CDECL

Keyword in a DECLARE statement (non-BASIC)

Worth knowing

Useful and cross-version information about the programming environments of QBasic and QuickBasic.

Description/Parameter(s)

CDECL in a DECLARE statement that declares a non-BASIC procedure indicates that the declared procedure uses the C-language argument order. QuickBASIC will pass the arguments in the argument list from right to left, rather than from left to right as is the BASIC convention.

Description/Parameter(s)
  • In a DECLARE statement that declares a non-BASIC procedure, CDECL indicates that the declared procedure uses the C-language argument order. BASIC passes the arguments in the argument list from right to left, rather than from left to right as is the usual BASIC convention.
Example

This example uses the DECLARE statement to use a C function in a BASIC program. The BASIC program calls the function addone, which uses C argument passing and takes a single integer argument passed by value.
Note: To run this program, you must separately compile the C function and place it in a Quick library or link it to the BASIC program.

DEFINT A-Z DECLARE FUNCTION addone CDECL (BYVAL n AS INTEGER) INPUT x y = addone(x) PRINT "x and y are "; x; y END '/* C function addone. Returns one more than the value of its argument. */ ' 'int far addone(int n) '{ ' return(n+1); '}