(07-07-2022 07:05 AM)EdS2 Wrote: [ -> ]Wow - very impressive! Might you share your code?
Thanks for your interest! Please see the new thread
Lisp in 99 lines of C.
I found some undocumented features of the C compiler. These were probably omitted from the PC-G850(V)(S) manual by accident.
PC-G850(V)(S) manual omissions
P.78 section 8.6.3 does not mention the ternary ?: and comma , operators of C.
a ? b : c gives b if a is true otherwise gives c
a , b evaluates both a and b, but gives the value of b (*)
*)
Do not call void-returning functions as operands of the comma operator, this will cause issues.
P.87 The C
scanf(),fscanf(),sscanf() support
%n conversion, which is not mentioned:
%n Number of characters converted (*)
int
For example,
sscanf("123#", "%d%n", &n, &i) assigns 123 to n and 3 to i.
*)
The %n conversion value is only set if the input could not be completely scanned: sscanf("123", "%d%n", &n &i) assigns 123 to %n but does not assign a value to i. Workaround: set i to strlen() before sscanf().
P.101 the
beep() C function is missing in this section:
void beep (unsigned tone, unsigned duration, unsigned number)
Function: beep sound
Note the different parameter order compared to
BEEP in Basic! See Basic
BEEP for a description of the function.
P.101 the
sizeof() function is missing in this section:
int sizeof(type)
int sizeof(expression)
Function: size of a type
Returns the size in bytes of the specified type or the size of the type of the specified expression. For example,
sizeof(int) and
sizeof(7) both return 2.
P.171 Basic function
MDF is missing in this section:
MDF
MDF expression
See also:
USING
Function: Modification function
Description: Returns the value of expression modified to the current
USING format. See also Section 3.1.
The first one above is very important and useful. The second one is useful to replicate libc functions, such as
strtol(), strtoul(), strtof(), strtod(), atol(), atoi() here listed in compact form to save space (please don't write C this way):
long strtol(const char*s,char**t,int b){long x;int n=strlen(s);sscanf(s,b==8?"%lo%n":b==16?"%lx%n":"%ld%n",&x,&n);if(t)*t=s+n;return x;}
unsigned long strtoul(const char*s,char**t,int b){unsigned long x;int n=strlen(s);sscanf(s,b==8?"%lo%n":b>10?"%lx%n":"%lu%n",&x,&n);if(t)*t=s+n;return x;}
float strtof(const char*s,char**t){float x;int n=strlen(s);sscanf(s,"%g%n",&x,&n);if(t)*t=s+n;return x;}
double strtod(const char*s,char**t){double x;int n=strlen(s);sscanf(s,"%lg%n",&x,&n);if(t)*t=s+n;return x;}
long atol(const char*s){return strtol(s,0,0);};
#define atoi atol
For example,
strtol() supports decimal, octal and hex bases
b and sets string pointer
t to the point where conversion ended in the string
s, if
t!=NULL.
- Rob
Edit: fixed typo