This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Strange thing with static Array!


Thank you very much

things now looks very clear to me by your discussions
and this will change my view about open source world

Thank you all

On Sat, Feb 28, 2009 at 7:34 PM, Bob Plantz <plantz@cds1.net> wrote:
> On Sat, 2009-02-28 at 12:06 -0500, me22 wrote:
>
>>
>> GCC allows the Variable Length Arrays feature from C99 in C++ as an extension.
>>
>> Consider compiling with -ansi -pedantic
>>
>> ~ Scott
>
> You can see what the compiler is doing for you if you look at the
> assembly language. Here is the part where the array gets allocated on
> the stack (with my comments added):
> ? ? ? ?call ? ?_ZNSirsERi ? ? ? ? # cin >> array_size
> ? ? ? ?movl ? ?-12(%rbp), %eax ? ?# load array_size
> ? ? ? ?cltq ? ? ? ? ? ? ? ? ? ? ? # convert long to quad
> ? ? ? ?subq ? ?$1, %rax ? ? ? ? ? # make sure the new stack
> ? ? ? ?addq ? ?$1, %rax ? ? ? ? ? # ? pointer meets all the
> ? ? ? ?salq ? ?$2, %rax ? ? ? ? ? # ? alignment specs.
> ? ? ? ?addq ? ?$15, %rax
> ? ? ? ?addq ? ?$15, %rax
> ? ? ? ?shrq ? ?$4, %rax
> ? ? ? ?salq ? ?$4, %rax
> ? ? ? ?subq ? ?%rax, %rsp ? ? ? ? # allocate the array
> ? ? ? ?movq ? ?%rsp, -48(%rbp) ? ?# and save pointer to it
>
> I did this on an x86-64 system in 64-bit mode, and I did not worry
> through the alignment code to see exactly what's going on. In
> particular,
> ? ? ? subq $1, %rax
> ? ? ? addq $1, %rax
> is pretty weird. But the real point is where the array gets allocated on
> the stack.
>
> - Bob
>
>
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]