delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/06/27/13:45:14

From: Kent Dahl <kentda AT stud DOT ntnu DOT no>
Newsgroups: comp.os.msdos.djgpp,comp.lang.c,comp.lang.c++,comp.lang.c
Subject: Re: DJGPP reserves wrong int size
Followup-To: comp.os.msdos.djgpp
Date: Wed, 27 Jun 2001 19:43:21 +0200
Organization: NTNU
Lines: 60
Message-ID: <3B3A1B39.F4D0F58B@stud.ntnu.no>
References: <9dde68b7 DOT 0106241053 DOT 2a385311 AT posting DOT google DOT com>
NNTP-Posting-Host: v128a.studby.ntnu.no
Mime-Version: 1.0
X-Trace: tyfon.itea.ntnu.no 993663640 1060 129.241.150.128 (27 Jun 2001 17:40:40 GMT)
X-Complaints-To: usenet AT itea DOT ntnu DOT no
NNTP-Posting-Date: Wed, 27 Jun 2001 17:40:40 +0000 (UTC)
X-Mailer: Mozilla 4.72 [en] (X11; U; Linux 2.2.14-5.0 i686)
X-Accept-Language: en
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

ZMAN wrote:
> int main ()
> {
> int i;
> i = 0x12345678;
> }

 
> 00000000 55                          push ebp
> 00000001 89E5                        mov ebp,esp
> 00000003 83EC04                      sub esp,byte +0x18
> 00000006 C745FC78563412              mov dword [ebp-0x4],0x12345678
> 0000000D C9                          leave
> 0000000E C3                          ret
> 
> The third line reserves 18 bytes.

Does it? First of all, its 0x18 bytes, aka 24 bytes.
Are you sure it isn't just padding for alignment?

If I add yet another int, the number doesn't increase...

<CODE>
int main () 
{
int i;
i = 0x12345678;
int j;
j = 0xCAFEBABE;
}
</CODE>

<ASM>
0x80483c0 <main>:       push   %ebp
0x80483c1 <main+1>:     mov    %esp,%ebp
0x80483c3 <main+3>:     sub    $0x18,%esp
0x80483c6 <main+6>:     movl   $0x12345678,0xfffffffc(%ebp)
0x80483cd <main+13>:    movl   $0xcafebabe,0xfffffff8(%ebp)
0x80483d4 <main+20>:    xor    %e
</ASM>

I'm using G++ 2.95.2 on Red Hat Linux, disassembling with GDB.

I can go up to 4 ints, and still the 0x18 doesn't change. 
On the fifth int, I get 0x28. On the ninth int, I get 0x38.
See a pattern? 

> And it should reserve 4 bytes because thats the size of an int right?

Is it? Thats platform dependant according to the C++ standard. 

And with that, I believe this question is off-topic for comp.lang.c++
(and c.l.c too) so I set FUT to comp.os.msdos.djgpp.

-- 
<[ Kent Dahl ]>================<[ http://www.stud.ntnu.no/~kentda/ ]>
  )____(stud.techn.;ind.øk.data)||(softwareDeveloper.at(Trustix))_( 
 /"Opinions expressed are mine and not those of my Employer,      "\
( "the University, my girlfriend, stray cats, banana fruitflies,  " )
 \"nor the frontal lobe of my left cerebral hemisphere.           "/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019