Oxygen Basic
Programming => Problems & Solutions => Topic started by: Emil_halim on February 01, 2014, 10:18:58 AM
-
Hi Charles,
this code compiled okay , but crashed when run it.
includepath "$\inc\"
$filename "test1.exe"
#include "RTL32.inc"
#include "console.inc"
includepath ""
#include once "msvcrt.inc"
struct point
{
int x
int y
}
function GetMEM(long x) as void*
return malloc(x)
end function
int main()
{
point* pt;
pt = GetMEM(sizeof point)
printf( "%d\n" , pt.x )
waitkey
}
main
1- what wrong with this code ?
2- when compiling zilb there was "->" ,[c operator], and oxygen compiled it without error.
when replace pt.x in my example with pt->x oxygen give error, why?
thanks for help.
edited:
is there a c++ style operator "new" so
pt = GetMEM(sizeof point)
will be
pt = new point
-
Hi Emil,
msvcrt.inc ?
Currently, OxygenBasic does not support arrow notation, and generally does not use explicit pointers in the main body of code. Also, array variables in C ire treated as pointers, but not in O2.
This is how to explicitly allocate memory to a pointer variable, and to free it when finished.
includepath "$\inc\"
$filename "test1.exe"
#include "RTL32.inc"
#include "console.inc"
includepath ""
struct point
{
int x
int y
}
int main()
{
point *pt
&pt=getmemory sizeof point
print pt.x cr
waitkey
freememory &pt
}
main
Using Let syntax:
int main()
{
let pt=new point
print pt.x cr
waitkey
freememory @pt
}
-
Hi Charles,
msvcrt.inc is include file for msvcrt.dll library i got it from old oxygenbasic , so i was test it with O2.
/* MSVCRT FOR OXYGENBASIC BY PETER WIRBELAUER 12.o8.2o12 */
sys msv
msv= LoadLibrary "msvcrt.dll"
Bind msv
(
abort abort
abs abs
acos acos
asctime asctime
asin asin
atan atan
atan2 atan2
atexit atexit
.... .....
.... ...etc....
and generally does not use explicit pointers in the main body of code.
why not , is there a technical reason ?
Also, array variables in C ire treated as pointers, but not in O2.
may you can add this feature later , when you have a spare time.
does Let keyword support array declaration with the new operator?
i mean that
Lest pt = new point[10] // allocates sizeof point structure * 10
thanks for help.
-
Hi Emil,
I am thinking about supporting C-pointers and C array conventions. But these cannot be reconciled directly with OxygenBasic's conventions, where pointers and references are generally abstracted out. Therefore we would have to switch into a different mode of syntax, supporting the full C language core.
There is a new release in the pipeline supporting dynamic arrays in let statements. It can be used with primitive variables and flat types, (but not strings). I need a bit more time to test it.