October 31, 2025, 11:44:40 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Casting problem

Started by Ficko, November 04, 2009, 03:07:16 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ficko

Is there a particular reason why "#<STRING>MySub0002()" is technically incorrect?  :o


OPENCONSOLE
DEF S:STRING
DEF T:POINTER
PRINT MySub0001()
T = MySub0002()
PRINT #<STRING>T
'PRINT #<STRING>MySub0002()  'undefined variable??
WAITCON
END

SUB MySub0001 (),STRING
RETURN "MySub0001"
ENDSUB

SUB MySub0002 (),POINTER
S = "MySub0002"
RETURN &S
ENDSUB


Ionic Wind Support Team

Because Emergence syntax doesn't support dereferencing a function directly, never has.

Ionic Wind Support Team

Ficko

Quote...dereferencing a function directly...

When you say it that way it sounds really sophisticated I would say "dereferencing a return value". :D

Ionic Wind Support Team

Parker and I had a discussion about it a while back regarding Aurora.  And I eventually gave in and added the capability to Aurora since it supports typed pointers....


sub main()
{
print( *test() );
while (GetKey() = "");
return;
}

sub test(),string *
{
return &"hello";
}


The discussion was how I felt it really was an unsafe "feature" of languages to allow this since there is no possibility of error checking for a null pointer before the dereference.  Imagine a function that returns a pointer to an allocated string, you have to worry about deleting the string or if it is NULL and would end up assigning it to a variably anyway.

Paul.
Ionic Wind Support Team

Ficko

November 05, 2009, 02:06:48 AM #4 Last Edit: November 05, 2009, 02:11:35 AM by Ficko
It's ok I found a solution works for me.

Since you already have INT() I just introduced STRING_(). ;)

However I run into an other casting Q.
What this: "*<STRING>&MyString[0]" good for?
Certainly I did expect a char to get. :o


OPENCONSOLE
DECLARE MyString
DECLARE STRING_(str:POINTER),STRING
DEF S:STRING
S ="HelloString"

PRINT STRING_(MySub001())
PRINT STRING_(&MyString)
PRINT *<STRING>&MyString
PRINT *<STRING>&MyString[0]
PRINT *<STRING>&MyString[1]
WAITCON
END

SUB MySub001(),POINTER
RETURN &S
ENDSUB

_asm
STRING_:mov eax,[esp+4]
retn 4
_endasm

_asm
segment .data
MyString:
db "HeloMemory",0
_endasm