Skip to content

请教 ch3-05-control-flow if跳转问题 #532

@ahcometrue

Description

@ahcometrue
  • 汇编代码
#include "textflag.h"
TEXT ·If(SB), NOSPLIT, $0-32
    MOVQ ok+8*0(FP), CX // ok
    MOVQ a+8*1(FP), AX  // a
    MOVQ b+8*2(FP), BX  // b

    CMPQ CX, $0         // test ok
    JZ   L              // if ok == 0, goto L
    MOVQ AX, ret+24(FP) // return a
    RET

L:
    MOVQ BX, ret+24(FP) // return b
    RET
  • go代码
func If(ok int, a, b int) int {
    if ok == 0 { goto L }
    return a
L:
    return b
}

运行时报错:

# command-line-arguments
duplicated definition of symbol assembly/func.If

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions