delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/12/28/03:10:42

From: bchapman_nojunk_ AT feist DOT com (BJC)
Newsgroups: comp.os.msdos.djgpp
Subject: Array Addressing Bug in DJGPP 2.02 with GCC 2.81 ???
Message-ID: <MPG.10f0f90c10857f59989685@news.feist.com>
X-Newsreader: MicroPlanet Gravity v2.10
Lines: 49
Date: Mon, 28 Dec 1998 02:11:55 -0600
NNTP-Posting-Host: 198.247.6.149
X-Trace: newsfeed.slurp.net 914832526 198.247.6.149 (Mon, 28 Dec 1998 02:08:46 CDT)
NNTP-Posting-Date: Mon, 28 Dec 1998 02:08:46 CDT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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