-
• #2
...since there is no C preprocessor to resolve
#define
- see Caveats in 'Inline C code', there is also no #include. The issue is that the service the way it is implemented right now would not know from where to include from... May be this could change when callbakc-url could be passed and you can serve your things to include by a (public) Web server... (you are exposing your dev source thru http). -
• #3
Sun 2018.08.26
Yeah, read that but on:
http://www.espruino.com/Compilation
What works and what doesn't?
Works
Maths, string operationsWhat part of using a math function isn't 'Maths' ?
and wasn't sure if an extension was similar to a module
http://www.espruino.com/Extending+Espruino+1
#include referenced there, so went on a hunch
Wonder if I could accomplish the same task with a function that iterates using brute force += multiplication? Hmmmm -
• #4
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+EspruiĀno+1 is about compiling your own version if Espruino - in which case you can include what you want.
The preprocessor is disabled because:
- 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
.If I were doing it, I'd:
- Google
c implementation of pow
- Copy the code from https://stackoverflow.com/questions/101439/the-most-efficient-way-to-implement-an-integer-based-power-function-powint-int
Paste it into the example from http://www.espruino.com/InlineC
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.
- it's a potential security hole (
Sun 2018.08.26
I am attempting to write some simple inline C functions. Was able to get the first snippet 'How do I use it' to compile and run.
http://www.espruino.com/InlineC
I'm now attempting the 'C' pow() function but wonder where to place the #include statement
#include
Wouldn't you know it, this post machine wont allow the lt math.h gl symbology
#include <math.h>
Not under: either
http://www.espruino.com/Compilation
It can't be placed outside the
var c = E.compiledC(
block as it's not recognized as Javascript, and placing it inside results in this compiler msg:Need the insight of someone that's been down this path.
A pow er user ;-)
Thankx