V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
codists
V2EX  ›  Go 编程语言

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

  •  
  •   codists ·
    codists · 2023-02-07 10:09:27 +08:00 · 1689 次点击
    这是一个创建于 434 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    第 1 条附言  ·  2023-02-07 15:24:55 +08:00
    一并感谢楼上各位大佬的解答,明白了。
    9 条回复    2023-02-07 15:16:44 +08:00
    loading
        1
    loading  
       2023-02-07 10:16:55 +08:00 via Android   ❤️ 1
    目标架构

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

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

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

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

    无论如何,这就是一句开头简介而已,对我而言无必要深究。
    cavivie
        6
    cavivie  
       2023-02-07 13:14:51 +08:00   ❤️ 1
    个人理解,machine code 和 assembly code 有时候都称为 native code ,instructions in the native machine language 表述的是 native code ,所以含义不言而喻。
    icyalala
        7
    icyalala  
       2023-02-07 13:45:50 +08:00   ❤️ 1
    像 Java 编译后是字节码,是平台无关的,是需要 VM 来执行的,这种叫 managed code 。
    native 想要说明的就是 go 编译后是平台的机器码,是只能跑在某种具体架构上的,由 CPU 直接执行的。
    比如你编译的 target arch 是 x86 ,那就跑不到 arm 里的 (除非再转译或者模拟)。
    apake
        8
    apake  
       2023-02-07 14:35:16 +08:00   ❤️ 1
    go 编译出来的是 可以直接执行的二进制程序, 包含的是物理机本身的指令, 不是字节码, 不需要 vm, 和 C 一样. native machine language 指这个.
    ysc3839
        9
    ysc3839  
       2023-02-07 15:16:44 +08:00 via Android   ❤️ 1
    就是字面意思,“原生机器语言”,意思是 Go 不像一般的 Java 或 C#那样要虚拟机来执行。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   955 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 21:43 · PVG 05:43 · LAX 14:43 · JFK 17:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.