Solved

Newbie : Linux Word Size...

Posted on 2002-06-21
2
377 Views
Last Modified: 2012-06-21
I'm running Linux (2.4.9) on an Intel box and trying to determine what is going on with this test :

Very simply, I have a function in C that goes as follows :

void f() {
  char buf[7];
}

When compiling to assembly via gcc -S and looking at the output, I see the function looks as follows :

f:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $24, %esp
        leave
        ret

Why is the assembly subtracting 24 bytes for a 7 byte buffer?  I know it has to be word aligned, but when I change buf[7] -> buf[8] I get the expected results :

f:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp
        leave
        ret

Shouldn't buf[7] produce the same output?

Thanks,
Steve
0
Comment
Question by:smisk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 50 total points
ID: 7101454
It could make sense if your compiler options were set for debug build.   Compilers often put guard bytes in the stack frame so that in a post-mortem analysis, a good tool can point out where your program clobbered the stack.

With VC++, with release mode optimization, the function f() evaluates to one opcode C3 (return).  With all optimization off, it shows
    sub esp,8
but in Debug build, it shows
    sub esp,48h

and it fills that gap (which includes the auto variable  buf) with 0xcc bytes.

-- Dan




0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Why thread specific data got introduced? 7 353
Binary/Hexadecimal conversion 8 633
DOS function for Text Windows size 8 311
CRM 2011 Custom Code 4 75
Configuring Remote Assistance for use with SCCM
Invest in your employees with these five simple steps to improve employee engagement and retention.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question