Oxygen Basic
Programming => Problems & Solutions => Topic started by: Emil_halim on January 31, 2014, 09:39:14 AM
-
Hi Charles,
i was playing with test example in C_code
here is my code
includepath "$inc\"
$ filename "test.exe"
#include "RTL32.inc"
#include "MinWin.inc"
includepath ""
#preprocess // allow C-style preprocessing
#include c.inc
typedef struct
{
float x;
float y;
}Point;
float hypo(float x,float y)
{
return sqr( x * x + y * y );
}
int f(int n)
{
return n;
}
int main()
{
int i;
int q=4;
Point p<={3,4};
float r;
r=hypo(p.x, p.y);
for (i=0; i<10; i++)
{
if (q==7) ++q;
q++
}
print (q); //result 15
return 0;
}
main
when compiling i get that error
Linker found unidentified names:
ExitProcess: level 0
GetExitCodeProcess: level 0
getModuleHandle: level 0
also when putting #preprocess in c.inc file i got unidentified #preprocess ?
any help please.
-
Hi Emil, I don't have your c.inc.
Place #preprocess at the top.
Couldn't quite cope with raw C, but I might be able to fix this in future releases. (around the for() statement.)
#preprocess // allow C-style preprocessing
includepath "$inc\"
$ filename "test.exe"
#include "RTL32.inc"
#include "MinWin.inc"
includepath ""
'#include c.inc
typedef struct
{
float x;
float y;
}Point;
float hypo(float x,float y)
{
return sqr( x * x + y * y );
}
int f(int n)
{
return n;
}
int main()
{
int i;
int q=4;
Point p<={3,4};
float r;
r=hypo(p.x, p.y);
for i=0; i<10; i++ // ( )
{
if (q==7) {++q}; // { }
q++
}
print (q); //result 15
return 0;
}
main
-
Hi Charles,
here is the c.inc
#case sensitive
#indexbase 0
#unique on
#autodim off
'#noinit
#semicolon separator
#assign on
it 's old oxygen basic file
-
Good! That works now without the the bracket alterations.
#semicolon separator was required.
-
Better would be we had an OxyC and oBasic stays untouched.
-
okay , works fine now.
thank you Charles.
Hi Peter
what is wrong with extending Oxygenbasic to deal with c code?
-
H Charles,
just i have a question , the #preprocess directive will allow OxygenBasic to deal with c_style PreProcess.
so if we are in some code that belong to basic code block and temporarily we disable C_style PreProcess ,
how to make that.
i think you can add On/Of parameter for #preprocess directive.
what do you think?
-
I though about this issue for some time. It would cause too many complications. But there is a fair compromise:
macro and def are not handled by the preprocessor, so they can be deployed wherever localised/scoped macros are required, instead of #define or % or $.
-
Better would be we had an OxyC and oBasic stays untouched.
Preventing change is like holding your breath. You can do neither for long.
-
I though about this issue for some time. It would cause too many complications. But there is a fair compromise:
macro and def are not handled by the preprocessor, so they can be deployed wherever localised/scoped macros are required, instead of #define or % or $.
yes , it very good solution , so at any time we can use "Def" & "Macro" as usual.
thanks you very much.
-
Hi Charles,
Oxygen basic compile this c code "part from zip library" without any error.
/* adler32.c -- compute the Adler-32 checksum of a data stream
* Copyright (C) 1995-2003 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id: adler32.c,v 1.1 2005/12/04 10:16:16 irrlicht Exp $ */
#define ZLIB_INTERNAL
#include "zlib.h"
#define BASE 65521UL /* largest prime smaller than 65536 */
#define NMAX 5552
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
#define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
#define DO16(buf) DO8(buf,0); DO8(buf,8);
#ifdef NO_DIVIDE
#define MOD(a) \
do { \
if (a >= (BASE << 16)) a -= (BASE << 16); \
if (a >= (BASE << 15)) a -= (BASE << 15); \
if (a >= (BASE << 14)) a -= (BASE << 14); \
if (a >= (BASE << 13)) a -= (BASE << 13); \
if (a >= (BASE << 12)) a -= (BASE << 12); \
if (a >= (BASE << 11)) a -= (BASE << 11); \
if (a >= (BASE << 10)) a -= (BASE << 10); \
if (a >= (BASE << 9)) a -= (BASE << 9); \
if (a >= (BASE << 8)) a -= (BASE << 8); \
if (a >= (BASE << 7)) a -= (BASE << 7); \
if (a >= (BASE << 6)) a -= (BASE << 6); \
if (a >= (BASE << 5)) a -= (BASE << 5); \
if (a >= (BASE << 4)) a -= (BASE << 4); \
if (a >= (BASE << 3)) a -= (BASE << 3); \
if (a >= (BASE << 2)) a -= (BASE << 2); \
if (a >= (BASE << 1)) a -= (BASE << 1); \
if (a >= BASE) a -= BASE; \
} while (0)
#else
#define MOD(a) a %= BASE
#endif
/* ========================================================================= */
uLong ZEXPORT adler32(adler, buf, len)
uLong adler;
const Bytef *buf;
uInt len;
{
unsigned long s1 = adler & 0xffff;
unsigned long s2 = (adler >> 16) & 0xffff;
int k;
if (buf == Z_NULL) return 1L;
while (len > 0) {
k = len < NMAX ? (int)len : NMAX;
len -= k;
while (k >= 16) {
DO16(buf);
buf += 16;
k -= 16;
}
if (k != 0) do {
s1 += *buf++;
s2 += s1;
} while (--k);
MOD(s1);
MOD(s2);
}
return (s2 << 16) | s1;
}
so does Oxygen supports old c function parameters?
i mean this
uLong ZEXPORT adler32(adler, buf, len)
uLong adler;
const Bytef *buf;
uInt len;
{
-
Curly-Brace languages are very popular, so I thought we might benefit from some of their notation. :)
I advise caution when diving straight into this kind of code. Much testing remains to be done!
I have posted another update, with some fixes relevant to C: (about 4 hours ago)
http://www.oxygenbasic.org/forum/index.php?topic=749.0
-
Hi Charles,
after updating , some c source code need stdio.h and i found it in inc/glo2 folder.
so why you do not put it in the root inc folder?
-
There are a few dummy files stored in /inc/glo2 to allow gl.h to be used directly, without editing.