什么是“ the native machine language of a computer”?

2023-02-07 10:09:27 +08:00
 codists

如标题所示,这句话出自《 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 )? 希望各位大佬帮忙解答以下。

1773 次点击
所在节点    Go 编程语言
9 条回复
loading
2023-02-07 10:16:55 +08:00
目标架构

不同架构有不同指令集,所以如果就简单直接转通用机器码不是最优解,所以 golang 会区分架构编译吧?

我也没深入研究。
sunjiayao
2023-02-07 10:31:57 +08:00
之前编译 go 的时候。是可以通过交叉编译直接编译成目标架构的可执行文件,扔上去就能跑不需要任何依赖。
xuyang2
2023-02-07 11:07:36 +08:00
flyqie
2023-02-07 12:36:25 +08:00
个人觉得其实说白了就是 jvm 与 go runtime 的区别。

两者对于运行时(可能叫法不准确)的功能概念是不一样的。
vanillacloud
2023-02-07 13:12:36 +08:00
其只说是「 native 原生」 machine language of a computer ,而 machine language 就是 binary instructions ( 0s and 1s )指令集。

由于每种处理器理解的 instruction 不一样,所以它这句话也可能示意了其会直接编译成目标架构的指令集。

无论如何,这就是一句开头简介而已,对我而言无必要深究。
cavivie
2023-02-07 13:14:51 +08:00
个人理解,machine code 和 assembly code 有时候都称为 native code ,instructions in the native machine language 表述的是 native code ,所以含义不言而喻。
icyalala
2023-02-07 13:45:50 +08:00
像 Java 编译后是字节码,是平台无关的,是需要 VM 来执行的,这种叫 managed code 。
native 想要说明的就是 go 编译后是平台的机器码,是只能跑在某种具体架构上的,由 CPU 直接执行的。
比如你编译的 target arch 是 x86 ,那就跑不到 arm 里的 (除非再转译或者模拟)。
apake
2023-02-07 14:35:16 +08:00
go 编译出来的是 可以直接执行的二进制程序, 包含的是物理机本身的指令, 不是字节码, 不需要 vm, 和 C 一样. native machine language 指这个.
ysc3839
2023-02-07 15:16:44 +08:00
就是字面意思,“原生机器语言”,意思是 Go 不像一般的 Java 或 C#那样要虚拟机来执行。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/913818

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX