Golang Go语言中什么是“the native machine language of a computer”?
如标题所示,这句话出自《 The Go Programming Language 》第 1 页:
Go is a compiled language. The Go toolchain converts a source program and the things it
depends on into instructions in the native machine language of a computer. These tools are
accessed through a single command called go that has a number of subcommands. The sim-plest of these subcommands is run , which compiles the source code from one or more source files whose names end in .go , links it with libraries, then runs the resulting executable file.
现有以下疑问: ( 1 )“native”在这里想表达什么意思? ( 2 )“machine language of a computer”里面,machine language 在这里具体指什么(如:machine code )? 希望各位大佬帮忙解答以下。
Golang Go语言中什么是“the native machine language of a computer”?
更多关于Golang Go语言中什么是“the native machine language of a computer”?的实战教程也可以访问 https://www.itying.com/category-94-b0.html
目标架构
不同架构有不同指令集,所以如果就简单直接转通用机器码不是最优解,所以 golang 会区分架构编译吧?
我也没深入研究。
更多关于Golang Go语言中什么是“the native machine language of a computer”?的实战系列教程也可以访问 https://www.itying.com/category-94-b0.html
之前编译 go 的时候。是可以通过交叉编译直接编译成目标架构的可执行文件,扔上去就能跑不需要任何依赖。
个人觉得其实说白了就是 jvm 与 go runtime 的区别。
两者对于运行时(可能叫法不准确)的功能概念是不一样的。
其只说是「 native 原生」 machine language of a computer ,而 machine language 就是 binary instructions ( 0s and 1s )指令集。
由于每种处理器理解的 instruction 不一样,所以它这句话也可能示意了其会直接编译成目标架构的指令集。
无论如何,这就是一句开头简介而已,对我而言无必要深究。
个人理解,machine code 和 assembly code 有时候都称为 native code ,instructions in the native machine language 表述的是 native code ,所以含义不言而喻。
像 Java 编译后是字节码,是平台无关的,是需要 VM 来执行的,这种叫 managed code 。
native 想要说明的就是 go 编译后是平台的机器码,是只能跑在某种具体架构上的,由 CPU 直接执行的。
比如你编译的 target arch 是 x86 ,那就跑不到 arm 里的 (除非再转译或者模拟)。
go 编译出来的是 可以直接执行的二进制程序, 包含的是物理机本身的指令, 不是字节码, 不需要 vm, 和 C 一样. native machine language 指这个.
就是字面意思,“原生机器语言”,意思是 Go 不像一般的 Java 或 C#那样要虚拟机来执行。
在Golang(Go语言)中,“the native machine language of a computer”指的是计算机能够直接理解和执行的机器语言。这是一种由二进制代码(0和1的序列)组成的低级编程语言,是计算机硬件能够直接解读和运行的指令集。
Go语言,作为一种高级编程语言,与机器语言有着显著的区别。Go语言提供了更高级、更抽象的编程结构和语法,使得开发者能够更便捷地编写复杂的应用程序。然而,这些高级代码在运行时需要被编译成机器语言,才能被计算机执行。
Go语言的编译器负责将Go源代码转换为目标平台的机器语言。这个过程包括词法分析、语法分析、语义分析、中间代码生成、代码优化和目标代码生成等多个阶段。最终,编译器会生成一个可执行的二进制文件,该文件包含了计算机能够直接运行的机器指令。
因此,虽然Go语言本身不是机器语言,但它能够通过编译器有效地转换为机器语言,从而在计算机上高效运行。这种转换过程是高级编程语言实现跨平台兼容性和提高开发效率的关键所在。