Author Topic: pointer issue.  (Read 1200 times)

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

  • Guest
pointer issue.
« on: August 19, 2019, 07:17:04 PM »
Other variables can be declared in the same row, just by separating them with a comma,
not pointers. Pointers wont work when declaring them that way... even worse, they fail silently.

 Also, you can use chr() with a byte pointer variable alone, but if you append more numbers
the function gets broken.

Code: [Select]
    string s1 = "A"
    string s2 = "B"
    string s3 = "C"

    byte ptr p1
    byte ptr p2, p3  ' p3 pointer is broken.
     
    @p1 = StrPtr(s1)
    @p2 = StrPtr(s2)
    @p3 = StrPtr(s3)
   
    print chr(p1) chr(13, 10)
    print chr(p2) chr(13, 10)
    print chr(p3) chr(13, 10)
   
    ' print chr(p1, 13, 10) ' Compilation time error.

Aurel

  • Guest
Re: pointer issue.
« Reply #1 on: August 19, 2019, 10:35:12 PM »
As far as i know there is no POINTER variable type in o2.

Arnold

  • Guest
Re: pointer issue.
« Reply #2 on: August 20, 2019, 12:10:15 AM »
Hi Brian,

this will work for me:

sys ptr p2, ptr p3   (or byte ptr )
or
sys *p2, *p3      (or byte * )

I also think that this is more logical:

print chr(65,13,10)
or
print chr(p1)  chr(13, 10)

I am surprised that byte * does work, I thought there is a difference between char and byte?

Roland
« Last Edit: August 20, 2019, 01:30:38 AM by Arnold »

Charles Pegge

  • Guest
Re: pointer issue.
« Reply #3 on: August 20, 2019, 03:30:16 AM »
Yes, ptr and '*' are interchangeable, and these are associated with each variable rather than the type itself.

I'll need to trap impossible address assignments:

byte b
@b=strptr s



The variadic form of chr will only work with numbers, but if you need something more flexible:
Code: [Select]
'12:07 20/08/2019
'variadic chr
function chrs(int n,...) as string
if n>0
  function=nuls n
  byte b at @param 'param base on stack
  byte c at strptr function
  while n
    @b+=sizeof sys 'next param on stack
    c=b
    @c++
    n--
  wend
endif
end function
'
byte a=0x41 'A
byte b=0x42
byte c=0x43
print chrs(5,a,b,c,0x44,0x45) 'ABCDE'