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…')
 
m (5 revisions imported)
 
(4 intermediate revisions by the same user not shown)
Line 9: Line 9:
 
== Example ==
 
== Example ==
  
  var pid:Int :: allocated[multiple[]] :: directref[];
+
  function void main() {
  ccode["pid=(int) getpid();","","#include <sys/types.h>","#include <unistd.h>"];
+
    var pid:Int :: allocated[multiple[]] :: directref[];
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.
+
''Since: Version 0.5''
  
 
[[Category:Type Library]]
 
[[Category:Type Library]]
[[Category:Composite Types]]
+
[[Category:Compound Types]]
 
[[Category:Attribute Types]]
 
[[Category:Attribute Types]]

Latest revision as of 15:44, 15 April 2019

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

function void main() {
   var pid:Int :: allocated[multiple[]] :: directref[];
};

Since: Version 0.5