go - Does Golang run on a virtual machine? -
say simple golang code:
package main import "fmt" func plus( int, b int) int { return a+b } func plusplus(a,b,c int) int { return +b + c } func main() { ptr := plus ptr2 := plusplus fmt.println(ptr) fmt.println(ptr2) } this has following output:
0x2000 0x2020 what going on here? doesn't function pointer, or kind of pointer matter, 1 find in stack. understand go, while offering nice low level functionality in threading department, requires os function; c functional across computer platforms , operating systems can written in while go needs operating system function , in fact works on few os right now. regular function pointers mean works on vm? or compiler linked low level c functions?
go not run on virtual machine.
from view of language specification, ptr , ptr2 function values. can called ptr(1, 2) , ptr2(1, 2, 3).
diving down implementation, variables ptr , ptr2 pointers func values. see function call design document information on func values. note distinction between language's "function" value , implementation's "func" value.
because relflection api used fmt package indirects through func values pointer print, call tofmt.println(ptr) prints actual address of plus function.
Comments
Post a Comment