Difference between revisions of "Directref"

From Mesham
Jump to navigationJump to search
(Created page with '== 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 per…')
 
Line 10: Line 10:
  
 
  var pid:Int :: allocated[multiple[]] :: directref[];
 
  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.
 
  
 
[[Category:Type Library]]
 
[[Category:Type Library]]
 
[[Category:Composite Types]]
 
[[Category:Composite Types]]
 
[[Category:Attribute Types]]
 
[[Category:Attribute Types]]

Revision as of 16:37, 12 January 2013

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[];