小编Bus*_*uss的帖子

在C中,将struct作为参数传递给printf的预期行为是什么?

第二次尝试

好吧,也许我第一次尝试提问这个问题太混乱了.所以,我们再来一次......

在一个带有可变数量参数的函数中,比如printf,当你传递一个struct时,你应该期望生成什么样的代码?

基于这段代码,我问这个问题:

#include <stdio.h>

struct edge{
    int v1, v2;
};

int main(void){
    struct edge edges;

    edges.v1=5;
    edges.v2=20;

    printf("'%d'\n",  edges);

return 0;
}
Run Code Online (Sandbox Code Playgroud)

在我的Windows框中编译时,它传递2个整数参数:

    .file   "simple_test_case2.c"
    .def    ___main;    .scl    2;  .type   32; .endef
    .section .rdata,"dr"
LC0:
    .ascii "'%d'\12\0"
    .text
.globl _main
    .def    _main;  .scl    2;  .type   32; .endef
_main:
    pushl   %ebp
    movl    %esp, %ebp
    andl    $-16, %esp
    subl    $32, %esp
    call    ___main
    movl    $5, 24(%esp)
    movl    $20, 28(%esp)
    movl    24(%esp), %eax
    movl    28(%esp), %edx
    movl    %eax, 4(%esp) …
Run Code Online (Sandbox Code Playgroud)

c gcc struct code-generation

2
推荐指数
1
解决办法
1228
查看次数

标签 统计

c ×1

code-generation ×1

gcc ×1

struct ×1