delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/12/28/04:35:38

From: "Hagbart Data" <hagbartdata AT post DOT tele DOT dk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Array Addressing Bug in DJGPP 2.02 with GCC 2.81 ???
Date: Mon, 28 Dec 1998 10:29:23 +0100
Lines: 71
Message-ID: <767j2a$304q$1@news-inn.inet.tele.dk>
References: <MPG DOT 10f0f90c10857f59989685 AT news DOT feist DOT com>
NNTP-Posting-Host: ip93.hinxr1.ras.tele.dk
X-Trace: news-inn.inet.tele.dk 914837386 98458 (None) 195.249.198.93 (28-12-98 09:29:46 GMT)
X-Newsreader: Microsoft Outlook Express 4.72.3110.5
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

No bug.

try this:
for (i=0;i< sizeof(str2);i++)

and think.

OK the size is 4, but from 0 to 4 incl. = 5.

good luck

BJC skrev i meddelelsen ...
>I still consider myself a begginer to C so maybe somebody can tell me whats
going on. I'm
>running a fresh install of DJGPP v2.02 with GCC v2.81. In the following
code i declare an
>array (str1) and initilize it to "TEST" and then i declare a second array
(str2). The problem
>is that the last element of str2 is allocated the same address as the first
element of str1.
>
>----------------------------------------------------------------------
>#include <stdio.h>
>int main (void)
>{
> char str1[] = "TEST";
> char str2[4];
> int i;
> for (i=0;i<=sizeof(str2);i++)
> printf("str2[%d] (%#xd) = \"%c\"\n",i,&str2[i],str2[i]);
> for (i=0;i<=sizeof(str1);i++)
> printf("str1[%d] (%#xd) = \"%c\"\n",i,&str1[i],str1[i]);
> return;
>}
>----------------------------------------------------------------------
>
>this program prints out the following:
>
>------------------------
>str2[0] (0x8ecc4d) = " "
>str2[1] (0x8ecc5d) = " "
>str2[2] (0x8ecc6d) = " "
>str2[3] (0x8ecc7d) = " "
>str2[4] (0x8ecc8d) = "T"      <------------ same address
>str1[0] (0x8ecc8d) = "T"      <------------ same address
>str1[1] (0x8ecc9d) = "E"
>str1[2] (0x8eccad) = "S"
>str1[3] (0x8eccbd) = "T"
>str1[4] (0x8ecccd) = " "
>str1[5] (0x8eccdd) = " "
>------------------------
>
>Can anyone confirm this? Is this a bug? It took me some 4 hours to track
this down. :S
>I guess there is a problem with GCC 2.81 allocating and PUSHing the arrays
onto the stack(??)
>
>i compiled this program with DJGPP 2.01 and PGCC 1.01 and all was
well...infact it left 2
>bytes space between str2 and str1.
>
>but i am wanting to use latest versions of things....AAAAHHHHHHHHH!!!! Help
me
>sombody...PLEASSE! =8S
>
>
>--
>brian james chapman
>email: bchapman(at)feist(dot)com


- Raw text -


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