extern "rtlib"

Forum for discussion about the documentation project.
Site Admin
Posts: 3170
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada

extern "rtlib"

Postby coderJeff » Sep 02, 2019 12:58

Recently added in fbc 1.08 is the extern "rtlib" block:

* fbc: add extern "rtlib"

- add extern "rtlib" block, to make convenient, declaring functions within fb source code, but defined in fb's rtlib
- combines the behaviour of extern "c" with fbc default calling convention
- used in a namespace, has the effect of respecting the namespace within fb source code while also linking to regular C function

documentation updated in wiki: EXTERN...END EXTERN

For example, rtlib has function fb_MemCopyClear() that wraps a crt memcpy() call followed by a memset() call.

Code: Select all

namespace FB
   extern "rtlib"
      declare sub MemCopyClear alias "fb_MemCopyClear"_
         ( _
            byval dst as any ptr, _
            byval dstlen as integer, _
            byval src as const any ptr, _
            byval srclen as integer _
   end extern
end namespace

dim src as zstring * 10 = "FreeBASIC"
dim dst as zstring * 10 = "012345678"

print "before:"
print "src = " & src
print "dst = " & dst

'' copy first 4 bytes and clear the rest
FB.MemCopyClear( @dst, sizeof(dst), @src, 4 )

print "after:"
print "src = " & src
print "dst = " & dst


Code: Select all

src = FreeBASIC
dst = 012345678

src = FreeBASIC
dst = Free

Updating ASM documentation only insofar as default calling conventions are concerned.

Return to “Documentation”

Who is online

Users browsing this forum: No registered users and 7 guests