Revision history for ProPgStringsTypes


Revision [26777]

Last edited on 2024-03-07 03:29:37 by fxm [since fbc version 1.20.0, STRING*N occupies N bytes and has no terminating null character]
Additions:
Output example before fbc version 1.20.0 and for win64 (a wstring character uses 2 bytes):
Deletions:
Output example for win64 and before fbc version 1.20.0 (a wstring character uses 2 bytes):


Revision [26776]

Edited on 2024-03-07 03:26:13 by fxm [since fbc version 1.20.0, STRING*N occupies N bytes and has no terminating null character]
Additions:
since fbc version 1.20.0, total length of the string: '//size//' characters = '//size//' bytes ##('//size//' useful characters)##
before fbc version 1.20.0, total length of the string: '//size//+1' characters = '//size//+1' bytes ##('//size//' useful characters + '1' final null character)##
' Result depending on fbc version (before/since 1.20.0)
Dim As ZString * 20 z20 = "FreeBASIC manual"
Dim As ZString Ptr pz = @"FreeBASIC manual"
Dim As WString * 20 w20 = "FreeBASIC manual"
Dim As WString Ptr pw = @WStr("FreeBASIC manual")
Print Using "'FIXED-LENGTH STRING * 20': ## bytes in total, ## useful characters available"; SizeOf(s20); Len(s20)
#if __FB_VERSION__ < "1.20.0"
Print Using " containing ## user characters of # byte(s) each"; IIf(InStr(s20, Chr(0)) > 0, InStr(s20, Chr(0)) - 1, Len(s20)); SizeOf(s20[0])
#endif
Print Using "'FIXED-LENGTH ZSTRING * 20': ## bytes in total, ## useful characters available"; SizeOf(z20); SizeOf(z20) \ SizeOf(z20[0]) - 1
Print Using " containing ## user characters of # byte(s) each"; Len(z20); SizeOf(Z20[0])
Print Using " containing ## user characters of # byte(s) each"; Len(*pz); SizeOf((*pz)[0])
Print Using "'FIXED-LENGTH WSTRING * 20': ## bytes in total, ## useful characters available"; SizeOf(w20); SizeOf(w20) \ SizeOf(w20[0]) - 1
Print Using " containing ## user characters of # byte(s) each"; Len(w20); SizeOf(w20[0])
Print Using " containing ## user characters of # byte(s) each"; Len(*pw); SizeOf((*pw)[0])
Type descriptor : Addr As ZString Ptr : UC As UInteger : AC As UInteger : End Type
Print Using "'STRING': ## bytes in descriptor, memory allocated for ## characters right now"; SizeOf(s); Cast(descriptor Ptr, @s)->AC
Print Using " containing ## user characters of # byte(s) each"; Len(s); SizeOf(s[0])
(hence the formula only for fixed-length string type before fbc version 1.20.0: ##'""user_characters_length = IIf(InStr(s, Chr(0)) > 0, InStr(s, Chr(0)) - 1, Len(s))""'##)
Output example for win64 and before fbc version 1.20.0 (a wstring character uses 2 bytes):
Deletions:
total length of the string: '//size//+1' characters = '//size//+1' bytes ##('//size//' useful characters + '1' final null character)##
Dim As Zstring * 20 z20 = "FreeBASIC manual"
Dim As Zstring Ptr pz = @"FreeBASIC manual"
Dim As Wstring * 20 w20 = "FreeBASIC manual"
Dim As Wstring Ptr pw = @Wstr("FreeBASIC manual")
Print Using "'FIXED-LENGTH STRING * 20': ## bytes in total, ## useful characters available"; Sizeof(s20); Len(s20)
Print Using " containing ## user characters of # byte(s) each"; Iif(Instr(s20, Chr(0)) > 0, Instr(s20, Chr(0)) - 1, Len(s20)); Sizeof(s20[0])
Print Using "'FIXED-LENGTH ZSTRING * 20': ## bytes in total, ## useful characters available"; Sizeof(z20); Sizeof(z20) \ Sizeof(z20[0]) - 1
Print Using " containing ## user characters of # byte(s) each"; Len(z20); Sizeof(Z20[0])
Print Using " containing ## user characters of # byte(s) each"; Len(*pz); Sizeof((*pz)[0])
Print Using "'FIXED-LENGTH WSTRING * 20': ## bytes in total, ## useful characters available"; Sizeof(w20); Sizeof(w20) \ Sizeof(w20[0]) - 1
Print Using " containing ## user characters of # byte(s) each"; Len(w20); Sizeof(w20[0])
Print Using " containing ## user characters of # byte(s) each"; Len(*pw); Sizeof((*pw)[0])
Type descriptor : Addr As Zstring Ptr : UC As Uinteger : AC As Uinteger : End Type
Print Using "'STRING': ## bytes in descriptor, memory allocated for ## characters right now"; Sizeof(s); Cast(descriptor Ptr, @s)->AC
Print Using " containing ## user characters of # byte(s) each"; Len(s); Sizeof(s[0])
(hence the formula: ##'""user_characters_length = IIf(InStr(s, Chr(0)) > 0, InStr(s, Chr(0)) - 1, Len(s))""'##)
Output example for win64 (a wstring character uses 2 bytes):


Revision [23983]

Edited on 2020-06-30 07:19:52 by fxm [added paragraph (Implicit conversion from Zstring to Ubyte)]
Additions:
{{fbdoc item="section" value="Implicit conversion from Zstring to Ubyte"}}
When any operand of a binary operator (as assignment, equal, +, *, ...) consists in dereferencing a '##Zstring Ptr##' pointer ('##pz##'), this can give a '##Zstring##' string or a '##Ubyte##' variable, depending on the other operand:
**""-""** If the other operand is numeric, so the dereferenced '##Zstring Ptr##' pointer ('##*pz##') will be treated as a '##Ubyte##' reference to the one character pointed.
**""-""** If in this case a '##Zstring##' pointer indexing '##[]##' operator is used as dereferencing syntax ('##pz[n]##'), it is basically a short-cut version of the '##String##' indexing '##[]##' operator ('##(*pz)[n]##').
Since '##(*pz)[i]##' and '##pz[i][k]##' are always numeric (each an '##Ubyte##'), such equalities are true:
##pz[i] = (*pz)[i]##
##(*pz)[i] = pz[i]##
and even:
##pz[i+k] = pz[i][k]##
##pz[i][k] = pz[i+k]##
Simple code example with a dereferenced '##Zstring Ptr##' converted to an '##Ubyte##' reference (as operand of an 'assignment' operator and a '+' operator):
{{fbdoc item="filename" value="examples/manual/proguide/strings_types2.bas"}}%%(freebasic)
Dim As Zstring * (14+1) z = "FreeBASIC "
Dim As Zstring Ptr pz = @z
Print z
z[10] = Asc("2")
*(pz + 11) = Asc("0") '' *(pz + 11) is converted to an Ubyte reference
(*pz)[12] = Asc("1")
pz[13] = Asc("8") '' pz[13] is converted to an Ubyte reference
Print z
For I As Integer = 10 To 13
Print Str(z[I] - Asc("0"));
Next I
For I As Integer = 10 To 13
Print Str((*pz)[I] - Asc("0"));
Next I
For I As Integer = 10 To 13
Print Str(pz[I] - Asc("0")); '' pz[I] is converted to an Ubyte reference
Next I
%%Output:
FreeBASIC
FreeBASIC 2018
2018
2018
2018


Revision [23634]

Edited on 2019-10-01 23:48:05 by fxm [formatting]
Additions:
##(*)## The number of bytes 'k' used by a ##WSTRING## character depends on the platform.
Deletions:
##(*)## The number of bytes 'k' used by a ##WSTRING## character depends on the platform.


Revision [23632]

Edited on 2019-10-01 08:03:49 by fxm [added note in example]
Additions:
(hence the formula: ##'""user_characters_length = IIf(InStr(s, Chr(0)) > 0, InStr(s, Chr(0)) - 1, Len(s))""'##)


Revision [23631]

Edited on 2019-10-01 04:32:24 by fxm [wording]
Additions:
Of all built-in data-types, **Strings** types are those dedicated to the representation of character chains.
FreeBASIC supplies several strings data types for handling characters chains in various representations.
The fixed-length strings types (string, zstring and wstring) represent fixed-length chains of characters, while the variable-length string type represents a variable-length chain of characters.
total length of the pointed zstring: depends on the character chain referenced by the ##pointer## (up to and including the final null character)
total length of the pointed wstring: depends on the character chain referenced by the ##pointer## (up to and including the final null character)
Deletions:
Of all built-in data-types, **Strings** types are those dedicated to the representation of character sequences.
FreeBASIC supplies several strings data types for handling characters sequences in various representations.
The fixed-length strings types (string, zstring and wstring) represent fixed-length sequences of characters, while the variable-length string type represents a variable-length sequence of characters.
total length of the pointed zstring: depends on the character sequence referenced by the ##pointer## (up to and including the final null character)
total length of the pointed wstring: depends on the character sequence referenced by the ##pointer## (up to and including the final null character)


Revision [23630]

Edited on 2019-10-01 03:47:41 by fxm [added note on example]
Additions:
- Fixed-length string type for 8 bit character (QB-style fixed-length string):
Print Using " containing ## user characters of # byte(s) each"; Iif(Instr(s20, Chr(0)) > 0, Instr(s20, Chr(0)) - 1, Len(s20)); Sizeof(s20[0])
%%Note: For the fixed-length string type only (QB-style fixed-length string), the 'Len()' keyword always returns the declared constant number of characters, regardless of the number of characters assigned to it by user.

Output example for win64 (a wstring character uses 2 bytes):
Deletions:
- Fixed-length string type for 8 bit character:
Print Using " containing ## user characters of # byte(s) each"; Instr(s20, Chr(0)) - 1; Sizeof(s20[0])
%%Output example for win64 (a wstring character uses 2 bytes):


Revision [23629]

Edited on 2019-10-01 00:16:09 by fxm [typo]
Additions:
- Fixed-length zstring type for 8 bit character:
Deletions:
- Fixed-length zstring type 8 bit character:


Revision [23628]

Edited on 2019-09-30 10:08:18 by fxm [new page created]
Additions:
{{fbdoc item="title" value="Strings (string, zstring, and wstring)"}}----
Dim As String * 20 s20 = "FreeBASIC manual"
Dim As Zstring * 20 z20 = "FreeBASIC manual"
Dim As Zstring Ptr pz = @"FreeBASIC manual"
Dim As Wstring * 20 w20 = "FreeBASIC manual"
Dim As Wstring Ptr pw = @Wstr("FreeBASIC manual")
Dim As String s = "FreeBASIC manual"
Print Using "'FIXED-LENGTH STRING * 20': ## bytes in total, ## useful characters available"; Sizeof(s20); Len(s20)
Print Using " containing ## user characters of # byte(s) each"; Instr(s20, Chr(0)) - 1; Sizeof(s20[0])
Print
Print Using "'FIXED-LENGTH ZSTRING * 20': ## bytes in total, ## useful characters available"; Sizeof(z20); Sizeof(z20) \ Sizeof(z20[0]) - 1
Print Using " containing ## user characters of # byte(s) each"; Len(z20); Sizeof(Z20[0])
Print "'ZSTRING PTR': dereferencing pointer -> "; """" & *pz & """"
Print Using " containing ## user characters of # byte(s) each"; Len(*pz); Sizeof((*pz)[0])
Print
Print Using "'FIXED-LENGTH WSTRING * 20': ## bytes in total, ## useful characters available"; Sizeof(w20); Sizeof(w20) \ Sizeof(w20[0]) - 1
Print Using " containing ## user characters of # byte(s) each"; Len(w20); Sizeof(w20[0])
Print "'WSTRING PTR': dereferencing pointer -> "; """" & *pw & """"
Print Using " containing ## user characters of # byte(s) each"; Len(*pw); Sizeof((*pw)[0])
Print
Type descriptor : Addr As Zstring Ptr : UC As Uinteger : AC As Uinteger : End Type
Print Using "'STRING': ## bytes in descriptor, memory allocated for ## characters right now"; Sizeof(s); Cast(descriptor Ptr, @s)->AC
Print Using " containing ## user characters of # byte(s) each"; Len(s); Sizeof(s[0])
Sleep
'FIXED-LENGTH STRING * 20': 21 bytes in total, 20 useful characters available
containing 16 user characters of 1 byte(s) each
'FIXED-LENGTH ZSTRING * 20': 20 bytes in total, 19 useful characters available
containing 16 user characters of 1 byte(s) each
'ZSTRING PTR': dereferencing pointer -> "FreeBASIC manual"
containing 16 user characters of 1 byte(s) each
'FIXED-LENGTH WSTRING * 20': 40 bytes in total, 19 useful characters available
containing 16 user characters of 2 byte(s) each
'WSTRING PTR': dereferencing pointer -> "FreeBASIC manual"
containing 16 user characters of 2 byte(s) each
'STRING': 24 bytes in descriptor, memory allocated for 32 characters right now
containing 16 user characters of 1 byte(s) each
%%
Deletions:
{{fbdoc item="title" value="Strings (string, zstring, and wstring) (IN PROGRESS...)"}}----


Revision [23627]

Edited on 2019-09-30 07:47:04 by fxm [new page in progress...]
Additions:
There is only one type of variable-length string:
- Variable-length string type for 8 bit character:
Deletions:
There is only one type of variable-length string for 8 bit character:
- Variable-length string type:


Revision [23626]

Edited on 2019-09-30 07:46:18 by fxm [new page in progress...]
Additions:
There is only one type of variable-length string for 8 bit character:
Deletions:
There is only one type of variable-length string:


Revision [23625]

Edited on 2019-09-30 07:44:37 by fxm [new page in progress...]
Additions:
total length of the string: '//size//+1' characters = '//size//+1' bytes ##('//size//' useful characters + '1' final null character)##
total length of the zstring: '//size//' characters = '//size//' bytes ##('//size-1//' useful characters + '1' final null character)##
total length of the pointed zstring: depends on the character sequence referenced by the ##pointer## (up to and including the final null character)
total length of the wstring: '//size//' characters = '//size//' x k##(*)## bytes ##('//size-1//' useful characters + '1' final null character)##
total length of the pointed wstring: depends on the character sequence referenced by the ##pointer## (up to and including the final null character)

total length of the string: dynamic length depending on the assigned data characters
(string referenced by an internal descriptor of 1 ##pointer## + 2 ##uinteger## length)
Deletions:
total length: '//size//+1' characters = '//size//+1' bytes ##('//size//' useful characters + '1' final null character)##
total length: '//size//' characters = '//size//' bytes ##('//size-1//' useful characters + '1' final null character)##
total length: '//size//' characters = '//size//' x k##(*)## bytes ##('//size-1//' useful characters + '1' final null character)##


Revision [23622]

Edited on 2019-09-30 07:16:14 by fxm [new page in progress...]
Additions:
total length: '//size//' characters = '//size//' x k##(*)## bytes ##('//size-1//' useful characters + '1' final null character)##
##(*)## The number of bytes 'k' used by a ##WSTRING## character depends on the platform.
%%Output example for win64 (a wstring character uses 2 bytes):
Deletions:
total length: '//size//' characters = ##(*)## bytes ##('//size-1//' useful characters + '1' final null character)##
##(*)## the number of bytes used by a ##WSTRING## character depends on the platform.
%%Output example for win64 (64bit):


Revision [23620]

Edited on 2019-09-30 07:04:19 by fxm [new page in progress...]
Additions:
- Fixed-length string type for 8 bit character:
total length: '//size//+1' characters = '//size//+1' bytes ##('//size//' useful characters + '1' final null character)##
- Fixed-length zstring type 8 bit character:
total length: '//size//' characters = '//size//' bytes ##('//size-1//' useful characters + '1' final null character)##
- Fixed-length wstring type for wide character:
total length: '//size//' characters = ##(*)## bytes ##('//size-1//' useful characters + '1' final null character)##

##(*)## the number of bytes used by a ##WSTRING## character depends on the platform.
Deletions:
- Fixed-length string type:
- Fixed-length zstring type:
- Fixed-length wstring type:


Revision [23619]

Edited on 2019-09-30 04:54:58 by fxm [new page in progress...]
Additions:
**""-""** ##[[KeyPgString|STRING]] * //size//##
**""-""** ##[[KeyPgZstring|ZSTRING]] * //size//##
##or##
**""-""** ##[[KeyPgZstring|ZSTRING]] [[KeyPgPtr|PTR]]##
**""-""** ##[[KeyPgWstring|WSTRING]] * //size//##
##or##
**""-""** ##[[KeyPgWstring|WSTRING]] [[KeyPgPtr|PTR]]##
**""-""** ##[[KeyPgString|STRING]]##
Deletions:
**""-""** .....
**""-""** .....
**""-""** .....
**""-""** .....


Revision [23618]

Edited on 2019-09-30 04:25:11 by fxm [new page in progress...]
Additions:
Of all built-in data-types, **Strings** types are those dedicated to the representation of character sequences.
FreeBASIC supplies several strings data types for handling characters sequences in various representations.
The fixed-length strings types (string, zstring and wstring) represent fixed-length sequences of characters, while the variable-length string type represents a variable-length sequence of characters.
There are 3 types of fixed-length strings:
- Fixed-length string type:
**""-""** .....
- Fixed-length zstring type:
**""-""** .....
- Fixed-length wstring type:
**""-""** .....
There is only one type of variable-length string:
- Variable-length string type:
**""-""** .....
Size (in bytes) of different strings from all types above:
{{fbdoc item="filename" value="examples/manual/proguide/strings_types.bas"}}%%(freebasic)
%%Output example for win64 (64bit):
%%
%%
- ##[[CatPgString|String Functions]]##
- ##[[TblVarTypes|Standard Data Type Limits]]##
Deletions:
.....
.....
.....
.....
.....
- .....


Revision [23616]

The oldest known version of this page was created on 2019-09-30 03:31:06 by fxm [new page in progress...]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode