Doing C in PowerBASIC.
As we are allowed to handle API wrappers, here is a collection of functions from a standard Windows DLL, MSVCRT.DLL which gives you a wide range of direct C runtime functions.
Being much more interested in the Power aspect of PB than the Flower, Flour or Sour aspects, its no big deal to write close to C using the C runtime and while the functions are nothing exciting, you DO get them for close to nothing and with just a little help from an already posted MACRO, you can do all sorts of useful things with the C runtime functions.
Much of the attraction of PowerBASIC is that it can do many styles of code from line numbered BASIC to truly wicked assembler and any damned thing you can call from a DLL including the full API function set.
Instead of trying to cripple a powerful language down to the "Mickey Mouse Club" BASIC of the distant past, it can be used to do close to anything in Win32.
Old BASIC
New Basic
Almost MASM
Pure API
C Runtime
Better MACRO engine than most C compilers
etc etc etc .....
PowerBASIC needs to be treated like crippleware like it needs an extra hole in the head.
Here is PB doing a passable imitation of C.
' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
#include "\basic\include\win32api.inc"
#include "vcrt.inc"
#include "funcs.bas"
' ------------------------------
' return address of BASIC string
' ------------------------------
MACRO FUNCTION sadd(quoted)
MACROTEMP bas
LOCAL bas as STRING
bas = quoted
END MACRO = StrPtr(bas)
' ------------------------------
' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
FUNCTION PBmain as LONG
LOCAL urv as DWORD
LOCAL srv as LONG
LOCAL pbuf as DWORD
LOCAL pmem as DWORD
LOCAL lf as DWORD
pbuf = cmalloc(1024) ' allocate some working memory
pmem = cmalloc(1024) ' and a spare buffer
lf = sadd(chr$(13,10))
' ---------------------------
' number - string conversions
' ---------------------------
' urv = catoi(sadd("123456"))
' ccputs(cultoa(urv,pbuf,10))
' ccputs lf
ccputs(cultoa(catoi(sadd("123456")),pbuf,10)) ' unsigned
ccputs lf
' srv = catol(sadd("-987654"))
' ccputs(cltoa(srv,pbuf,10))
' ccputs lf
ccputs(cltoa(catol(sadd("-987654")),pbuf,10)) ' signed
ccputs lf
' ---------------------------
' tokenise string
' ---------------------------
LOCAL nums as DWORD
LOCAL token as DWORD
nums = sadd("one two three four five six seven eight nine ten")
token = cstrtok(nums,sadd(" ")) ' get 1st string
while token <> 0
ccputs(token)
ccputs lf
token = cstrtok(0,sadd(" ")) ' loop through the rest
wEnd
' ---------------------------
' zero terminated string copy
' ---------------------------
cstrcpy(pmem,sadd("This is a test of C runtime string copy"))
ccputs(pmem)
ccputs lf
' ---------------------------
' string reverse
' ---------------------------
ccputs(sadd("Reverse string = "))
ccputs(cstrrev(sadd("abcdefghijklmnopqrstuvwxyz")))
ccputs lf
' ---------------------------
' zero terminated string length
' ---------------------------
urv = cstrlen(sadd("12345678901234567890"))
ccputs(sadd("String length = "))
ccputs(cultoa(urv,pbuf,10))
ccputs lf
cfree(pbuf) ' free the memory
cfree(pmem)
pause
End FUNCTION
' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤