
PB vs C
Re: PB vs C
Unsigned integers and types in pointers in PB are all I need to be happy with. 

Dawn will come inevitably.
Re: PB vs C
you can hack longs in c backend but not integersuseful wrote: Sun Sep 29, 2024 5:19 am Unsigned integers and types in pointers in PB are all I need to be happy with.![]()
Code: Select all
Global x.l,y.l
;redefine x to unsigned
!unsigned int g_x;
x = -1
y = 1
If x > y ;if x is unsigend its 4294967295
Debug x
Debug Hex(x)
Else ;if x is signed it's -1
Debug x
EndIf
Re: PB vs C
It is clear that the built-in C gives us a lot of convenient!
But I would like to see unsigned integers and pointers with the type directly in the PB.
But I would like to see unsigned integers and pointers with the type directly in the PB.
Code: Select all
Global x.l
;redefine x to unsigned
!unsigned int g_x;
x = MakeIPAddress(255,255,255,255)
Debug x
Debug Hex(x)
Code: Select all
Global x.lu, *px.lu
*px = @x
x = MakeIPAddress(255,255,255,255)
Debug x
Debug Hex(x)
Debug *px
Debug Hex(*px)
Dawn will come inevitably.
Re: PB vs C
yes but you still need to dereference a pointer by it's type as in debug *px\luuseful wrote: Sun Sep 29, 2024 6:55 am It is clear that the built-in C gives us a lot of convenient!
But I would like to see unsigned integers and pointers with the type directly in the PB.
Code: Select all
Global x.l ;redefine x to unsigned !unsigned int g_x; x = MakeIPAddress(255,255,255,255) Debug x Debug Hex(x)
Code: Select all
Global x.lu, *px.lu *px = @x x = MakeIPAddress(255,255,255,255) Debug x Debug Hex(x) Debug *px Debug Hex(*px)
because you may need to check that the pointer is set as in IF *px <> 0 ...
Re: PB vs C
Code: Select all
EnableExplicit
Global x.l
Global y.i
!unsigned int g_x;
!unsigned long long g_y;
x = 2147483647 + 1 ; max signed + 1
Debug x
y = 9223372036854775807 + 1 ; max signed + 1
Debug y ; UuuuPpppSsss -9223372036854775808
;but
Debug y - 9223372036854775807 ; 1
;!!!
y = 9223372036854775807 + 256 ; max signed + 256
Debug Hex(y)
Code: Select all
EnableExplicit
Define y.i
!unsigned long long v_y;
!v_y = 18446744073709551614;
Debug Hex(y)
y+1
Debug Hex(y)
Last edited by useful on Wed Oct 23, 2024 5:06 pm, edited 1 time in total.
Dawn will come inevitably.
Re: PB vs C
Yes, always a bit of angst when interfacing a C lib that uses UINT, ULONGLONG.
It's been a while since I asked. What was the reason to not have native support?

Code: Select all
; ; Type, Bytes, Min, Max, C Type
l.l[0] ; Long, 4, -2147483648, 2147483647, long, int (long & $FFFFFFFF = unsigned)
;;ul.ul[0] ; ULong, 4, 0, 4294967295, unsigned long, unsigned int, DWORD(C++)
i.i[0] ; Integer, 4, -2147483648, 2147483647, long, int(x86 or 32-bit),sizeof*
;i.i[0] ; Integer, 8, -9223372036854775808, 9223372036854775807, long long(x64 or 64-bit),sizeof*
q.q[0] ; Quad, 8, -9223372036854775808, 9223372036854775807, long long
;;uq.uq[0] ; UQuad, 8, 0, 18446744073709551615, unsigned long long, ULONGLONG
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: PB vs C
It does complicate things sometimes, ROR longs can't be done in PB because of the << >> SAL and SAR when you want SHL SHR and MOV instead of MOVSXDskywalk wrote: Wed Oct 23, 2024 4:47 pm Yes, always a bit of angst when interfacing a C lib that uses UINT, ULONGLONG.![]()
It's been a while since I asked. What was the reason to not have native support?
Code: Select all
Procedure RORL(t.l,n) ; easy enough to do with inline asm and c
CompilerIf #PB_Compiler_Backend = #PB_Backend_Asm
!mov rcx, [p.v_n]
!ror dword [p.v_t] , cl
CompilerElse
!unsigned int tt = (unsigned int) v_t;
!v_t = (unsigned int) ((tt >> v_n) | (tt << ((32) - v_n)));
CompilerEndIf
ProcedureReturn t
EndProcedure
;or use fasm macros to do unsigned shifts in PB
CompilerIf #PB_Compiler_Backend = #PB_Backend_Asm
Macro EnableUnsigned()
!macro SAR reg,var
!{
!shr reg,var
!}
!macro SAL reg,var
!{
!shl reg,var
!}
!macro MOVSXD reg,var
!{
!match =dword x , var
!\{ mov eax, var
!mov reg,rax \}
!}
EndMacro
Macro DisableUnsigned()
!purge SAR
!purge SAL
!purge MOVSXD
EndMacro
CompilerElse
Macro EnableUnsigned() : EndMacro
Macro DisableUnsigned() : EndMacro
CompilerEndIf
Macro _RORL(x,n) ;test ror long with fasm macros
EnableUnsigned()
x = ((x >> n) | (x << ((32) - n)))
DisableUnsigned()
EndMacro
Define x.l
x = 1 << 31
Debug rorl(x,8) ;use asm and inline c
;8388608
x = 1 << 31
_rorl(x,8) ;patch fasm to do unsigned
;8388608 asm
;-8388608 c backend
Debug x