Use an undefined variable

Thu Mar 6 18:09:00 GMT 2008

I have a question. This statement is accepted by the g++ compiler (v. 4.1.2,
under linux):

char c = 'a';
string s = s + c;

But the variable s is used before begin defined! Why? It's correct?

The program aborts when the statement is reached.
If we change the above code into:

string s = s + 'a';

the error changes. A segmentation fault is raised.
Can anyone tell me why the code is accepted?

Piero Zanetti

View this message in context:
Sent from the gcc - Help mailing list archive at

More information about the Gcc-help mailing list