FWH 2603 Compile Error

Post Reply
User avatar
RAMESHBABU
Posts: 668
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

FWH 2603 Compile Error

Post by RAMESHBABU »

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

User avatar
Antonio Linares
Site Admin
Posts: 44515
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: FWH 2603 Compile Error

Post by Antonio Linares »

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:

Code: Select all | Expand

#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
Post Reply