Pure FB Runtime Library (in progress)
Re: Pure FB Runtime Library (in progress)
> ... (all common knowledge)
Why, for Pete's sake, can't you ever admit, to have made a mistake?
Would probably make you look, a bit more human?
Why, for Pete's sake, can't you ever admit, to have made a mistake?
Would probably make you look, a bit more human?
Last edited by MrSwiss on Sep 28, 2017 10:52, edited 1 time in total.
Re: Pure FB Runtime Library (in progress)
doesn't (and shouldn't) compile:MrSwiss wrote:Code: Select all
VarPtr(array(0)) ' or VarPtr(LBound(array))
//edit: full test code:C:\test.bas(4) error 24: Invalid data types, for @ or VARPTR in 'print varptr(lbound(array))'
Code: Select all
dim array(10) as integer
print @array(0)
print varptr(lbound(array))
sleep
Ask that yourself :-P (before blaming others)MrSwiss wrote:Why, for Pete's sake, can't you ever admit, to have made a mistake?
Would probably make you look a bit more human?
Re: Pure FB Runtime Library (in progress)
It works very well, in a real example: (no errors!)St_W wrote:Ask that yourself :-P
Code: Select all
Dim As ULong colour(0 To ...) = { &hFF000000, &hFF3F3F3F, &hFF7F7F7F }
Print VarPtr(colour(0))
Sleep
Re: Pure FB Runtime Library (in progress)
The syntax problem is on the second line.MrSwiss wrote:VarPtr used as follows, on a array:Code: Select all
VarPtr(array(0)) ' or VarPtr(LBound(array))
Re: Pure FB Runtime Library (in progress)
OK, thanks, duly noted ...fxm wrote:The syntax problem is on the second line.
The first one, however, which proves the point, works ...
Re: Pure FB Runtime Library (in progress)
That proves nothing at all because "array (0)" is a particular element of array, and not the array itself.
When we have a string (s), we can use not only:
VarPtr(s[0]) '' address of the first element of the character string
but also:
StrPtr(s) '' start address of the character string
When we have a string (s), we can use not only:
VarPtr(s[0]) '' address of the first element of the character string
but also:
StrPtr(s) '' start address of the character string
Re: Pure FB Runtime Library (in progress)
Are you aware of the fact, that for practical use, both of them are identical?
VarPtr(s[0]) = VarPtr(s) -- the very same Address ...
A String is (sort of, apart from "header"), a array of UByte (ASCII-String only).
Only: VarPtr(s[n]) would be different ... (where: n > 0)
VarPtr(s[0]) = VarPtr(s) -- the very same Address ...
A String is (sort of, apart from "header"), a array of UByte (ASCII-String only).
Only: VarPtr(s[n]) would be different ... (where: n > 0)
Re: Pure FB Runtime Library (in progress)
Yes, these two entities have the same value, but they are entities of different types:
Code: Select all
Dim As String s
#print typeof(VarPtr(s[0]))
#print typeof(Strptr(s))
Fortunately, there is compatibility between "Ubyte Ptr" and "Zstring Ptr" for assignment, but not fully compatibility between "Ubyte" and "Zstring":Compiler wrote:UBYTE PTR
ZSTRING * 4 CONST PTR
Code: Select all
Dim As String s = "FreeBASIC"
#print typeof(VarPtr(s[0]))
#print typeof(Strptr(s))
Dim As Ubyte Ptr pu = Strptr(s) '' OK
Dim As Zstring Ptr pz = VarPtr(s[0]) '' OK
#print typeof(*VarPtr(s[0]))
#print typeof(*Strptr(s))
Dim As Ubyte u = *Strptr(s) '' OK
Dim As Zstring *10 z = *VarPtr(s[0]) '' error 24: Invalid data types
Compiler wrote:UBYTE PTR
ZSTRING * 4 CONST PTR
UBYTE
ZSTRING
.....\FBIde0.4.6r4_fbc1.06.0\FBIDETEMP.bas(11) error 24: Invalid data types.....
Re: Pure FB Runtime Library (in progress)
Now, that has nothing any longer to do, with the initial question, of:
"How to get the *start*-address of an array, with a FB-keyword?" since you stated:
@ is a *short-cut* of VarPtr ... (@ = symbol (for: "get address"), VarPtr = keyword)
"How to get the *start*-address of an array, with a FB-keyword?" since you stated:
@ is a *short-cut* of VarPtr ... (@ = symbol (for: "get address"), VarPtr = keyword)
Re: Pure FB Runtime Library (in progress)
I have a git repo for this project here: https://github.com/ImortisInglorian/fbrtLib
At this point I have only confirmed that it will compile with what I have. I have been going back and fixing bugs in my translations in older files as they crop up during the compile process. I am using posidenFB as my IDE and the project file for it is in the repo. I am compiling it as a static library as I figured that would make testing it much easier when I have something testable.
It is not in a usable state.
If you want to eye-ball the code and point out how stupid I am or how many errors I have made (please be specific), feel free. I have commented out things that are not yet needed, and left thing in that will not compile on a windows environment since that is what I am working in.
I am getting 5 to 6 files converted a day, which is not great, but it's what I can do and still get work done and have a life outside of work and coding.
At this point I have only confirmed that it will compile with what I have. I have been going back and fixing bugs in my translations in older files as they crop up during the compile process. I am using posidenFB as my IDE and the project file for it is in the repo. I am compiling it as a static library as I figured that would make testing it much easier when I have something testable.
It is not in a usable state.
If you want to eye-ball the code and point out how stupid I am or how many errors I have made (please be specific), feel free. I have commented out things that are not yet needed, and left thing in that will not compile on a windows environment since that is what I am working in.
I am getting 5 to 6 files converted a day, which is not great, but it's what I can do and still get work done and have a life outside of work and coding.
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: Pure FB Runtime Library (in progress)
Declaring an array of size N in C gives you N elements starting at 0, i.e. 0 through N-1.Imortis wrote:[abridged]
I assumed the first was just an array declare, roughly this in FB:Code: Select all
static FB_STR_TMPDESC fb_tmpdsTB[FB_STR_TMPDESCRIPTORS];
Code: Select all
dim fb_tmpdsTB(FB_STR_TMPDESCRIPTORS) as FB_STR_TMPDESC
So it's necessary to adjust the array subscripts:
Code: Select all
dim shared fb_tmpdsTB(0 to FB_STR_TMPDESCRIPTORS-1) as FB_STR_TMPDESC
'dim array(0 to N-1)' is/should be pretty much considered as an idiom in FB, since 'dim a(N)' doesn't do the same thing, and 'dim a(N-1)' looks weird.
Re: Pure FB Runtime Library (in progress)
Thanks counting_pine. Already fixed in my local version.counting_pine wrote:Declaring an array of size N in C gives you N elements starting at 0, i.e. 0 through N-1.Imortis wrote:[abridged]
I assumed the first was just an array declare, roughly this in FB:Code: Select all
static FB_STR_TMPDESC fb_tmpdsTB[FB_STR_TMPDESCRIPTORS];
Code: Select all
dim fb_tmpdsTB(FB_STR_TMPDESCRIPTORS) as FB_STR_TMPDESC
So it's necessary to adjust the array subscripts:(I can see you've already added the 'shared' in https://github.com/ImortisInglorian/fbr ... re.bas#L20)Code: Select all
dim shared fb_tmpdsTB(0 to FB_STR_TMPDESCRIPTORS-1) as FB_STR_TMPDESC
'dim array(0 to N-1)' is/should be pretty much considered as an idiom in FB, since 'dim a(N)' doesn't do the same thing, and 'dim a(N-1)' looks weird.
Re: Pure FB Runtime Library (in progress)
Okay, next question:
How is that valid? FixPart is a char array and spzAdd is a char pointer.
EDIT: Whoops, never mind. I accidentally removed a comma from the line of code.
EDIT #2: By the way: the code behind the "FORMAT" command is a real mess. There has got to be a better way to do it. Maybe after this project is finished I, or someone else, can take a stab at rewriting it.
Code: Select all
LenAdd = sprintf( ((pszAdd = FixPart), FixPart)"%d", fb_Day( value ) );
EDIT: Whoops, never mind. I accidentally removed a comma from the line of code.
EDIT #2: By the way: the code behind the "FORMAT" command is a real mess. There has got to be a better way to do it. Maybe after this project is finished I, or someone else, can take a stab at rewriting it.
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: Pure FB Runtime Library (in progress)
https://github.com/freebasic/fbc/blob/m ... mat.c#L843?
Potentially when writing in FB, it might be possible to simplify some code by using strings and string functions.
It might not be as fast or memory-efficient. But on the other hand, simpler implementations might be a better foundation for writing/testing more efficient code based on it.
I'd say, feel fee to make the code nicer/simpler if you want. It's one of the main advantages to be gained from writing in FB. It will also help the understanding of the code.
Potentially when writing in FB, it might be possible to simplify some code by using strings and string functions.
It might not be as fast or memory-efficient. But on the other hand, simpler implementations might be a better foundation for writing/testing more efficient code based on it.
I'd say, feel fee to make the code nicer/simpler if you want. It's one of the main advantages to be gained from writing in FB. It will also help the understanding of the code.
Re: Pure FB Runtime Library (in progress)
Wow, you've done a lot of work already! Have you tried running it at all?
I notice a mistake in the translation: you've been translating 'int' to 'integer', but the equivalent of C's 'int' in FB is 'long'.
Also, you need to wrap everything in Extern "C" if you're not doing that already.
I notice a mistake in the translation: you've been translating 'int' to 'integer', but the equivalent of C's 'int' in FB is 'long'.
Also, you need to wrap everything in Extern "C" if you're not doing that already.