it's a potential security hole (#include "/etc/passwd")
including things will almost certainly bring in a lot of extra code and/or memory requirements that will probably use enough RAM that it makes it unusable anyway.
I guess you're just compiling a pow function for fun? Because there's one already in Math.pow.
var c = E.compiledC(`
// int ipow(int,int)
int ipow(int base, int exp)
{
int result = 1;
for (;;)
{
if (exp & 1)
result *= base;
exp >>= 1;
if (!exp)
break;
base *= base;
}
return result;
}
`);
print(c.ipow(5,5));
As mentioned in InlineC though, you may have similar issues dealing with double arithmetic though, since the double maths functions won't get built in by default.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
http://www.espruino.com/Compilation is about compiling JS code, not inline C which is http://www.espruino.com/InlineC
http://www.espruino.com/Extending+Espruino+1 is about compiling your own version if Espruino - in which case you can include what you want.
The preprocessor is disabled because:
#include "/etc/passwd"
)I guess you're just compiling a pow function for fun? Because there's one already in
Math.pow
.If I were doing it, I'd:
c implementation of pow
Paste it into the example from http://www.espruino.com/InlineC
As mentioned in InlineC though, you may have similar issues dealing with double arithmetic though, since the double maths functions won't get built in by default.