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
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
314 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
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do I defuse  Phase_2 in bomblab 12 1,010
Creating EXE from Assembly Code 13 776
Divide by zero in C and Javascript 13 488
How to Building Five Part Assembly Name for Master Page Inherit 1 475
IT certifications are a concrete representation of continual learning on the part of the candidate.  Continual learning is necessary for the long term success of an IT professional, but are IT certifications the right path for you?
There's a lot of hype surrounding blockchain technology. Here's how it works and some of the novel ways it' s now being used - including for data protection.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

856 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