Hi,

Ok, here's a nice one.

Chris Spencer send me an email about the following problem in the 64 bit version of cFileSystem (see DF2020 preview libraries)
Compiling that library nowadays triggered the following compiler warning:

Code:
- Warning 4543: C:\....\Library\cFilesystem.pkg (ln 1494) Redefining function return type for GET_FILESIZE with BIGINT (first defined as LONGPTR)
 
    // Returns the file size of a file.
    // Returns -1 if an error occured.
    Function FileSize String sFilename Returns BigInt
        tsSearchResult[] lsSearchResult
        BigInt iRetval
A few notes:
- The compiler says it is defined as LONGPTR, whereas code complete says that it is defined as an integer.
Those are not the same length when you are compiling 64 bit!
- The function filesize is already defined in the runtime for the ftp functionality (cFtpTransfer). So it is not the same functionality and as it is in the runtime there is no way to exclude that.

I can change the return type to Longptr, but then the function won't return filesizes over 2 GB when compiling under 32 bit.

Another idea is to rename the function, but existing code will continue to compile as it is already predefined in the runtime.

I also cannot throw a warning for anywhere where the original FileSize function is used in an application as that only works for #COMMAND style code...

So for now I came up with the following workaround:

Code:
    // Returns the file size of a file.
    // Returns -1 if an error occured.
    // Use *this* instead of FileSize as it works for both 32 bit as well as 64 bit and can
    // always return filesizes over 2GB.
    Function FileSizeEx String sFilename Returns Bigint
        tsSearchResult[] lsSearchResult
        BigInt iRetval
        Get FileSearch sFilename DIRMODE_FILES_ONLY to lsSearchResult
        If (SizeOfArray(lsSearchResult) > 0) Begin
            Move lsSearchResult[0].biFileSize to iRetval
        End
        Else Begin
            Move -1 to iRetval
        End
        Function_Return iRetval
    End_Function

    // Returns the file size of a file.
    // Returns -1 if an error occured.
    // ** Don't USE THIS, but FileSizeEx above as this only works correctly for 64 bit.
    Function FileSize String sFilename Returns Longptr
      BigInt biSize
      Get FileSizeEx sFilename to biSize
      Function_Return biSize
    End_Function
A few remarks about that "solution" to get rid of the warning.

- On 32 bit the filesize function is broken for file sizes over 2GB in size if you don't change your code to use FileSizeEx instead.
- You also don't see this when compiling as I can not generate a compiler warning if you use FileSize instead of FileSizeEx somewhere. (throwing a runtime error is dangerous, so I am not even considering that)
- FileSizeEx works OK on both 32 bit as well as 64 bit whereas FileSize only works correct when compiling 64 bit.
- When compiling on 32 bit LongPtr is only 4 bytes whereas BigInt is 8 bytes, stuffing that 8 byte sized biSize in the return value really should trigger a compiler warning on 32 bit... The compiler is completely happy with the above (where it should NOT!)
- Bahhh.. "Ex" suffix naming (but what else?)

So while I now no longer have compiler warnings, the code is less clear and still has issues that -IMO- should throw a warning.

Right now, I'm not seeing a better solution that does not break existing code without getting rid of that warning...

Fun eh?
--
Wil