Solved

Number of bytes allocated for char arrays by subl %esp seems much too high (in linux 2.4, gcc 3.2.2)

Posted on 2003-12-06
7
321 Views
Last Modified: 2008-03-17
Hi!

I noticed that when I declare a buffer of, for example, char[5], the assembly code generated by gcc actually allocates a much larger buffer, in this case 24 bytes:

subl $24, (%esp)

How can this be explained?
0
Comment
Question by:dn6
[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
  • 3
7 Comments
 
LVL 22

Accepted Solution

by:
grg99 earned 43 total points
ID: 9888440
If you mean at function entry, the compiler might allocate some extra space to store temporary results, or to store registers, or to align the stack pointer, or to set up some kind of exception stack frame, or to pre-allocate some space needed in any variables declared in interior code blocks.  
0
 
LVL 37

Assisted Solution

by:bbao
bbao earned 41 total points
ID: 9893387
for static or constant char buffer, commonly the compiler may allocate same-size memory, or a bit more for memory alignment. for char buffer of a function, depends on its type, usage and how compiler push them into stack. for dynamic allocated char buffer, it needs extra memory for MCB, memory control block, it describes the size, type and other attributes of a memory block.

hope it helps,
bbao
0
 
LVL 5

Assisted Solution

by:mtmike
mtmike earned 41 total points
ID: 9897137
GCC aligns the stack pointer to a multiple of 16 bytes by default. You can change its behaviour using the -mpreferred-stack-boundary switch. For example, 'gcc -mpreferred-stack-boundary=2' forces gcc to align the stack pointer to a multiple of 2^2=4 bytes. Optimizing for size (-Os) has the same effect.
0
 
LVL 37

Expert Comment

by:bbao
ID: 9911073
yes, it depends on type, processor, operating system and even compiler.
0
 
LVL 37

Expert Comment

by:bbao
ID: 10054045
dn6, any feedback please?
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert from C to MIPS 14 1,437
Dword and Qword in PHP 5 1,026
NASM assembly program 18 983
How to find out if watchdog driver execution area is from ROM(Flash Memory) or RAM ? 1 396
Unified and professional email signatures help maintain a consistent company brand image to the outside world. This article shows how to create an email signature in Exchange Server 2010 using a transport rule and how to overcome native limitations …
We asked our MSP customer base what their favorite tools were and how they help them serve clients. We focused our questions on favorite tools in the following categories: >PSA tools >RMM tools >Alert management tools >Communication tools and Mo…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

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