Directref
Syntax
directref[ ]
Semantics
This tells the compiler that the programmer might use this variable outside of the language (e.g. Via embedded C code) and not to perform certain optimisations which might not allow for this.
Example
var pid:Int :: allocated[multiple[]] :: directref[]; ccode["pid=(int) getpid();","","#include <sys/types.h>","#include <unistd.h>"]; print["My Process ID is ",pid,"\n"];
The code example above illustrates how the Mesham programmer can easily include native C code in their program, using normal program variables. First the variable pid is declared to be an integer, allocated to all processes and that it will be referenced directly by native C. The ccode function then allows the programmer to code directly in C and uses the POSIX function getpid to obtain the process ID of the current program, which is cast as an integer and stored directly in variable pid. The last line, once again Mesham code, will display this process ID.