Harbour function in C function

174 views
Skip to first unread message

Srđan

unread,
Feb 17, 2025, 5:14:14 PMFeb 17
to Harbour Users
How to call the Harbor function in C and how to pass a parameter to the function ?

Daniel L. Stuardo S.

unread,
Jun 6, 2025, 2:24:32 PMJun 6
to harbou...@googlegroups.com
Hi, friend!

An example:

In Harbour:
    a:=10; b=0.5
    r := my_add( a, b )

In #Pragma:

HB_FUNC( MY_ADD )
{
         double nA = hb_param( 1, HB_IT_NUMERIC );
         double nB = hb_param( 2, HB_IT_NUMERIC );
         double r = nA + nB;
         hb_retnd( r );
}

In Harbour:
     a := {1,2,3,4,5,6}
     ? my_pow( a, 4 )

In #Pragma:

HB_FUNC( MY_POW )
{
       PHB_ITEM pArray = hb_param( 1, HB_IT_ARRAY );
       double nPower = hb_param( 2, HB_IT_NUMERIC );
       int i;
       double res;
       HB_MAXINT nLong = hb_arrayLen( pArray );

    /*  arrays on Harbour begin in 1 */
       PHB_ITEM newArray = hb_itemArrayNew( nLong );
       for ( i=1; i<=nLong; ++i ){
                PHB_ITEM pElem = hb_itemArrayGet( pArray, i );
                res = pow ( hb_itemGetND( pElem ),  (double) nPower );
                hb_arraySetND( newArray, i, res );
                hb_itemRelease( pElem );
        }
        hb_ret ( newArray );  // not remember hb_ret... ?? find in Harbour's source code.
        hb_itemRelease( newArray );
}

Google traductor: "nunca modifiques el contenido de un array pasado como parámetro: crea uno nuevo, y devuelve ese array"

More examples in all Harbour's source code!

Saludos!

El lun, 17 feb 2025 a las 19:14, 'Srđan' via Harbour Users (<harbou...@googlegroups.com>) escribió:
How to call the Harbor function in C and how to pass a parameter to the function ?

--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/harbour-users/29de43b7-4d4c-481f-b0f8-f7adad050f4fn%40googlegroups.com.


--
Cordialmente,
_______________________________
Daniel L. Stuardo
Reply all
Reply to author
Forward
0 new messages