Mail Archives: djgpp/1998/12/28/04:35:38
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 -