Onelong

分享知识,与你一起进步......
RSS icon Home icon
  • 结构体

    post by onelong / 2012-12-18 6:28 Tuesday [C++]

    c++代码:

     

    int main(int a, char** v)

    {

            struct point

            {

                    int n;

                    int x;

                    int y;

            };

     

            struct point pt;

            pt.x = 50;

            pt.y = 60;

    //      pt.n = 120;

    }

    汇编代码:

     

    .arch armv4t

    .fpu softvfp

    .eabi_attribute 20, 1

    .eabi_attribute 21, 1

    .eabi_attribute 23, 3

    .eabi_attribute 24, 1

    .eabi_attribute 25, 1

    .eabi_attribute 26, 2

    .eabi_attribute 30, 6

    .eabi_attribute 18, 4

    .file "ht.cpp"

    .text

    .align 2

    .global main

    .type main, %function

    main:

    .fnstart

    .LFB0:

    @ Function supports interworking.

    @ args = 0, pretend = 0, frame = 24

    @ frame_needed = 1, uses_anonymous_args = 0

    @ link register save eliminated.

    str fp, [sp, #-4]!

    .LCFI0:

    add fp, sp, #0

    .LCFI1:

    sub sp, sp, #28

    .LCFI2:

    str r0, [fp, #-24]

    str r1, [fp, #-28]

    mov r3, #50

    str r3, [fp, #-12]

    mov r3, #60

    str r3, [fp, #-8]

    mov r3, #0

    mov r0, r3

    add sp, fp, #0

    ldmfd sp!, {fp}

    bx lr

    .LFE0:

    .cantunwind

    .fnend

    .size main, .-main

    .ident "GCC: (ctng-1.6.1) 4.4.3"

    .section .note.GNU-stack,"",%progbits

    看c代码应该分配32b的内存,事实上是28b,结构体的n没有初始化也没有分配什么的。结构体在编译的时候会拆开,都是调用是分配内存的。至少我是这样理解的。

    标签: c c++ cpu arm 汇编
    引用地址:
     

    我要评论