OK but if size isn't optional why no error/warning message ?fxm wrote:How the compiler can guess your number of bytes (> 1) to read, by passing it a dereferenced byte pointer corresponding to one byte, therefore why a warning?
By the way the FB compiler and runtime could do something like this !
Joshy
Code: Select all
#include "crt.bi"
extern "C"
#ifdef __FB_LINUX__
declare function getBufferSize alias "malloc_usable_size" (byval p as any ptr) as size_t
#elseif defined(__FB_WIN32__)
declare function getBufferSize alias "_msize" (byval p as any ptr) as size_t
#else
#error 666: Build trarget must be Windows or Linux !
#endif
end extern
const fileName = "guitarra.QSF"
var hFile = FreeFile()
if open(fileName,for binary,access read,as hFile) then
print "error: can't read: '" & fileName & "' !"
beep:sleep:end 1
end if
dim as integer nBytes = lof(hFile)
print "file size: " & nBytes
dim as ubyte ptr fileBuffer=allocate(nBytes)
get #hFile,,*fileBuffer,getBufferSize(fileBuffer)
close hFile