FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour FWH 2603 Compile Error
Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
FWH 2603 Compile Error
Posted: Wed May 06, 2026 11:42 PM

Dear Mr.Antonio,

The function below is giving the following compilation errors. Please guide me
the solution.

I am using fwh2603+xHarbour+bcc70

Warning W8071 Source\\PRBLIB.PRG 15637: Conversion may lose significant digits in function HB_FUN_SET_DATE
Warning W8071 Source\\PRBLIB.PRG 15638: Conversion may lose significant digits in function HB_FUN_SET_DATE
Warning W8071 Source\\PRBLIB.PRG 15639: Conversion may lose significant digits in function HB_FUN_SET_DATE
*** 1 errors in Compile ***


********************************************************************************

*** C WRAPER FUNCTION Set_Date(dDate) - To Change System Date - An Alternate ***
*** to SetDate() * SYNTAN : Set_Date(yyyy, mm, dd) ***


********************************************************************************

#pragma BEGINDUMP
#include <windows.h>
#include "hbapi.h"

HB_FUNC(SET_DATE )

{
SYSTEMTIME st;
GetLocalTime(&st );
st.wYear = hb_parni(1 );
st.wMonth = hb_parni(2 );
st.wDay = hb_parni(3 );
hb_retl(SetLocalTime(&st));
}

#pragma ENDDUMP

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: FWH 2603 Compile Error
Posted: Thu May 07, 2026 02:18 AM

Dear Ramesh Babu,

The warnings are caused by assigning the return value of hb_parni() (which returns int) to SYSTEMTIME struct members (wYear, wMonth, wDay) which are of type WORD (unsigned short). BCC 7.0 is strict about implicit narrowing conversions from 32-bit int to 16-bit unsigned short.

The fix is to add explicit casts to WORD:

#pragma BEGINDUMP
#include <windows.h>
#include "hbapi.h"

HB_FUNC( SET_DATE )
{
   SYSTEMTIME st;
   GetLocalTime( &st );
   st.wYear  = ( WORD ) hb_parni( 1 );
   st.wMonth = ( WORD ) hb_parni( 2 );
   st.wDay   = ( WORD ) hb_parni( 3 );
   hb_retl( SetLocalTime( &st ) );
}

#pragma ENDDUMP

The ( WORD ) cast tells the compiler you intentionally want the narrowing conversion, which suppresses the W8071 warning. This is safe as long as you pass valid date values (year, month, day all fit within a 16-bit unsigned range).

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion