Author Topic: [SOLVED] Help w/ String Casts Pls  (Read 3605 times)

0 Members and 1 Guest are viewing this topic.

Mike Lobanovsky

  • Guest
[SOLVED] Help w/ String Casts Pls
« 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...)
« Last Edit: November 09, 2014, 03:56:56 AM by Mike Lobanovsky »

Charles Pegge

  • Guest
Re: Help w/ String Casts Pls
« Reply #1 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.  

Mike Lobanovsky

  • Guest
Re: [SOLVED] Help w/ String Casts Pls
« Reply #2 on: November 09, 2014, 03:58:42 AM »
Thanks Charles,

That helps. :)

Aurel

  • Guest
Re: [SOLVED] Help w/ String Casts Pls
« Reply #3 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 ?

Charles Pegge

  • Guest
Re: [SOLVED] Help w/ String Casts Pls
« Reply #4 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*)

JRS

  • Guest
Re: [SOLVED] Help w/ String Casts Pls
« Reply #5 on: November 12, 2018, 07:12:49 PM »
I love O2's autonomous strings! AI BASIC

Aurel

  • Guest
Re: [SOLVED] Help w/ String Casts Pls
« Reply #6 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
« Last Edit: November 12, 2018, 10:53:26 PM by Aurel »

JRS

  • Guest
Re: [SOLVED] Help w/ String Casts Pls
« Reply #7 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.

Aurel

  • Guest
Re: [SOLVED] Help w/ String Casts Pls
« Reply #8 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)

Charles Pegge

  • Guest
Re: [SOLVED] Help w/ String Casts Pls
« Reply #9 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.