I am responsible for Robert's sudden interest in this ancient thread.
I recently added a new function to BCX named LookAhead() that uses _ftelli64 and _fseeki64.
LookAhead performs perfectly when BCX is compiled with Mingw(g++), MSVC, Clang, Embarcadero, and Lcc-Win32
but I cannot even build BCX using Pelles C when LookAhead is in place. I've spent days trying to get an understanding of
what's happening. I went so far as to write replacement FTELL and FSEEK functions by using fsetpos() and fgetpos() but
whatever is happening to ftell and fseek affects those functions too. My replacements worked fine with the other compilers.
I sent Robert the following synopsis earlier this evening.
If ftell and fseek are NEVER used in a Pelles compiled program (including BCX),
everything works great. But as soon as those functions are called, other file related functions,
notably fgets() and possibly feof(), become corrupted somehow and malfunction.
But you might not see the corruption immediately.
It might take LINE INPUTTING hundreds of lines of source code, for example, before you can detect
the corruption. The corrupt lines (missing first character on the left) are actually corrupt
-BEFORE- they hit LookAhead(). Yep ... that was a surprise to me too. But it only occurs when
using a Pelles C compiled version of BCX. When BCX is built with all other compilers, LookAhead
and the rest of BCX works perfectly.
I've taken BCX 8.1.5, and added the following fixups to SUB Final_Transforms and then rebuilt BCX
using Pelles C. I was hoping to see some patterns, beyond the left-most character being gobbled up.
I don't see any other patterns.
DO WHILE NOT EOF(FP1)
LINE INPUT FP1, Source$
$IFDEF __POCC__
IF Source$ = "num" THEN Source$ = "enum"
IF LEFTSTR(Source$, "/ ") THEN Source$ = "/" + Source$
IF LEFTSTR(Source$, "IZE* ") THEN Source$ = "S" + Source$
IF LEFTSTR(Source$, "NT_PTR ") THEN Source$ = "I" + Source$
IF LEFTSTR(Source$, "RESULT CALL") THEN Source$ = "L" + Source$
IF LEFTSTR(Source$, "RESULT COM_") THEN Source$ = "I" + Source$
IF LEFTSTR(Source$, "WND BCX_") THEN Source$ = "H" + Source$
IF LEFTSTR(Source$, "_IMPORT ") THEN Source$ = "C" + Source$
IF LEFTSTR(Source$, "define ") THEN Source$ = "#" + Source$
IF LEFTSTR(Source$, "har *") THEN Source$ = "c" + Source$
IF LEFTSTR(Source$, "har* ") THEN Source$ = "c" + Source$
IF LEFTSTR(Source$, "ifndef ") THEN Source$ = "#" + Source$
IF LEFTSTR(Source$, "lass ") THEN Source$ = "c" + Source$
IF LEFTSTR(Source$, "loat ") THEN Source$ = "f" + Source$
IF LEFTSTR(Source$, "nt ") THEN Source$ = "i" + Source$
IF LEFTSTR(Source$, "oid ") THEN Source$ = "v" + Source$
IF LEFTSTR(Source$, "ong double") THEN Source$ = "l" + Source$
IF LEFTSTR(Source$, "ouble ") THEN Source$ = "d" + Source$
IF LEFTSTR(Source$, "tatic ") THEN Source$ = "s" + Source$
IF LEFTSTR(Source$, "ypedef ") THEN Source$ = "t" + Source$
$ENDIF
'******************************************************************************
' Do Some quick beautification of the output
'******************************************************************************
IF LTRIM$(Source$) = "" AND LTRIM$(LOOKAHEAD$(FP1)) = "" THEN ITERATE
IF LTRIM$(Source$) = "" AND LTRIM$(LOOKAHEAD$(FP1)) = "#endif" THEN ITERATE
'******************************************************************************
With those fixups, I successfully compiled BCX using Pelles and then used that version of BCX to successfully
compile well over 300 test apps, large and small. But I'm certain that the list of fixups can never be complete
nor is it even practical to have such fixups in an application. BCX has, until recently, never relied on FTELL or FSEEK,
so Pelles C was always a reliable testing tool. But my LookAhead() function has changed that. The work that
LookAhead() does is non-critical and could be skipped over like so in BCX:
$IFNDEF __POCC__
IF LTRIM$(Source$) = "" AND LTRIM$(LOOKAHEAD$(FP1)) = "" THEN ITERATE
IF LTRIM$(Source$) = "" AND LTRIM$(LOOKAHEAD$(FP1)) = "#endif" THEN ITERATE
$ENDIF
But I've never needed to do such a thing in BCX and I'm reluctant to start doing it now.
Sorry for the long post but it's been a very complicated subject for me to get to this point.