Oxygen Basic

Programming => Problems & Solutions => Topic started by: Mike Lobanovsky on November 09, 2014, 01:10:37 AM

Title: [SOLVED] Help w/ String Casts Pls
Post by: Mike Lobanovsky on November 09, 2014, 01:10:37 AM
Hi Charles,

I have sys p that is the pointer to an ASCIIZ string. How should I cast it in O2 in order to be able to print the corresponding ASCIIZ string using Oxygen's print statement? (hopefully it will also help me use sys pointers to ASCIIZ strings in other oxygenated permutations...)
Title: Re: Help w/ String Casts Pls
Post by: Charles Pegge on November 09, 2014, 02:16:26 AM
Hi Mike,

Code: OxygenBasic
  1.  
  2.  
  3. char  s[] = "hello"
  4. sys p = strptr s
  5.  
  6. print cast char *p     'DIRECT CAST
  7.  
  8. char z at p : print z  'USING POINTER VARIABLE
  9.  
Title: Re: [SOLVED] Help w/ String Casts Pls
Post by: Mike Lobanovsky on November 09, 2014, 03:58:42 AM
Thanks Charles,

That helps. :)
Title: Re: [SOLVED] Help w/ String Casts Pls
Post by: Aurel on November 12, 2018, 04:36:23 AM
Hi Charles
OK work with type CHAR
but why NOT work with type STRING ?
also with BSTRING compile but give strange result with random chars ?

look this :
Code: [Select]
'str pointer
string s = "ABA"
int p = strptr s

'print cast string *p ' direct casting NOT work?
'string z at p  -> not work
char z at p : print z

Is there any changes in new version from A043 ?
Title: Re: [SOLVED] Help w/ String Casts Pls
Post by: Charles Pegge on November 12, 2018, 06:53:07 PM
Hi Aurel,

A string has more attributes than a char*. It contains an ole string and is assigned to a garbage collection list, so you cannot cast a char* to be a string.

But you can get the char* of a string, and we rely on this when passing text params to Windows. (Strings are automatically down-converted to char*)
Title: Re: [SOLVED] Help w/ String Casts Pls
Post by: JRS on November 12, 2018, 07:12:49 PM
I love O2's autonomous strings! AI BASIC
Title: Re: [SOLVED] Help w/ String Casts Pls
Post by: Aurel on November 12, 2018, 10:39:13 PM
OK Charles
according to this site  :
https://www.dyclassroom.com/c/c-pointers-and-strings

real string in fact is type CHAR or array of chars or sequence of chars with null terminated
and i know that

and it is interesting if is true
there is no STRING data type in windows according to this site;
https://docs.microsoft.com/en-us/windows/desktop/winprog/windows-data-types
Title: Re: [SOLVED] Help w/ String Casts Pls
Post by: JRS on November 12, 2018, 11:15:24 PM
I think Charles made it clear that he isn't following anyone else definition of BASIC and defining his own. Compatibility with the outside world is considered in its design.
Title: Re: [SOLVED] Help w/ String Casts Pls
Post by: Aurel on November 13, 2018, 12:04:30 AM
John
I don't know how work with strings is solved internaly in other BASICS but there is a fact
that in most work as it should be.

Charles
I just tried this C example in Oxygen with CHAR
and work perfect in Oxygen  :D

Code: [Select]
'string - char pointer
char s[] = "ABA"
char *p = strptr s
print p + spanOf(s)
Title: Re: [SOLVED] Help w/ String Casts Pls
Post by: Charles Pegge on November 15, 2018, 02:40:45 AM
Basic usually has a native string type with a dynamically variable length, which is lacking in char arrays.