[BUG] Nested variables

Niall Smart njs3@doc.ic.ac.uk
Sun May 24 04:40:00 GMT 1998


On May 23,  4:27pm, Frank DENIS -Jedi/Sector One- wrote:
} Subject: [BUG] Nested variables
> 
>   I got some unexpected segmentation faults with the shadow password suite,
> when compiled with Egcs 1.0.3-release, due to a macro.
>
>   Basically, the problem can be reproduced as follows :
>   
> #include <stdio.h>
> 
> int main(void)
> {
>    const char *yop = "Yop";
>    
>    printf("Yop 1 = [%p]\n", yop);
>      {
> 	const char *yop = yop;	
> 	printf("Yop 2 = [%p]\n", yop);
>      }
>    
>    return 0;
> }
> 
>   With Egcs, yop1 and yop2 got different values. In fact, the nested 'yop'
> is not initialized at all :

This behaviour is correct, the scope of a variable extends from the 
"point of declaration; that is, after the complete declarator and
before the initializer.  This implies that a name can be used to
specify its own initial value." - Section 4.9.4 of TC++PL 3Ed

The example given in the book is:

int x;

void f3()
{
	int x = x;  // perverse: initialise x with its own (uninitialised) value
}

I hope this clears it up; the bug is in the shadow passwd suite,
not egcs.

Regards,

Niall



More information about the Gcc-bugs mailing list