Different result for ver 6.0 c backend and LTS

Just starting out? Need help? Post your questions and find answers here.
Allen
User
User
Posts: 92
Joined: Wed Nov 10, 2021 2:05 am

Different result for ver 6.0 c backend and LTS

Post by Allen »

Hi,

I got different results from below program for ver 6.0 c backend and LTS. Please help to confirm.
Further checking show it is related if the PB file is save with UTF-8 BOM or UTF-8 only. In my IDE setting PB file always save in UTF-8 BOM. Manually convert the PB file to UTF-8 format will solve the issue. (both compilers give the same result). However, I was told that PB file should always saved with UTF-8 BOM. My system is win 10 pro x64.

For below code, please compile without saving to disk and see if it make a difference.

Thanks.

Allen

Code: Select all

EnableExplicit

Define.i k,Tmp,Shift
Define.s Tmp$
Define.u TmpChar

Tmp$="*가";
Tmp=0
Shift=0
For k=1 To 2
  TmpChar=Asc(Mid(Tmp$,k,1))
  Tmp=Tmp+TmpChar<<Shift
  Shift=Shift+16
Next  
Debug Hex(Tmp)
;FFFFFFFFAC00002A   ver 6.0 c backend
;AC00002A  Ver 6.0 LTS

breeze4me
Enthusiast
Enthusiast
Posts: 511
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: Different result for ver 6.0 c backend and LTS

Post by breeze4me »

It seems to be a bug that occurs in the type cast of the variable.
The values of variable defined as "integer(8 bytes)" and variable defined as "quad" are different.

Code: Select all

CompilerIf #PB_Compiler_Backend <> #PB_Backend_C Or #PB_Compiler_Processor <> #PB_Processor_x64
  End
CompilerEndIf

EnableExplicit

Define.i k,Tmp,Shift
Define.s Tmp$
Define.u TmpChar

Tmp$="*가";
Tmp=0
Shift=0
For k=1 To 2
  TmpChar=Asc(Mid(Tmp$,k,1))
  Tmp=Tmp+TmpChar<<Shift
  Shift=Shift+16
Next  
Debug Tmp   ;-1409286102

Code: Select all

CompilerIf #PB_Compiler_Backend <> #PB_Backend_C Or #PB_Compiler_Processor <> #PB_Processor_x64
  End
CompilerEndIf

EnableExplicit

Define.i k,Shift
Define.s Tmp$
Define.u TmpChar

Define Tmp.q

Tmp$="*가";
Tmp=0
Shift=0
For k=1 To 2
  TmpChar=Asc(Mid(Tmp$,k,1))
  Tmp=Tmp+TmpChar<<Shift
  Shift=Shift+16
Next  
Debug Tmp   ;2885681194

Workaround:

Code: Select all

CompilerIf #PB_Compiler_Backend <> #PB_Backend_C Or #PB_Compiler_Processor <> #PB_Processor_x64
  End
CompilerEndIf

EnableExplicit

Define.i k,Shift
Define.s Tmp$
Define.u TmpChar

Define Tmp.q    ; <--  Define as Quad.

Tmp$="*가";
Tmp=0
Shift=0
For k=1 To 2
  TmpChar=Asc(Mid(Tmp$,k,1))
  Tmp=Tmp+TmpChar<<Shift
  Shift=Shift+16
Next  
Debug Hex(Tmp)    ;AC00002A
Allen
User
User
Posts: 92
Joined: Wed Nov 10, 2021 2:05 am

Re: Different result for ver 6.0 c backend and LTS

Post by Allen »

breeze4me,

Thanks for the explanation and example. For the time being, will it be more safe to use quad instead of integer for x64 C backend?

Thanks.

Allen Wong
breeze4me
Enthusiast
Enthusiast
Posts: 511
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: Different result for ver 6.0 c backend and LTS

Post by breeze4me »

Allen wrote: Mon Jun 27, 2022 1:03 pm For the time being, will it be more safe to use quad instead of integer for x64 C backend?
It may or may not be.
The C backend has a shorter history and is less verified than the asm backend. So there is no definite answer.
Nevertheless, it would be better to use the quad type for the part where the problem occurred.
Allen
User
User
Posts: 92
Joined: Wed Nov 10, 2021 2:05 am

Re: Different result for ver 6.0 c backend and LTS

Post by Allen »

breeze4me,

Thanks for the suggestion, will test with more old programs with the new c backend complier.

Allen
Post Reply