Re: Use an undefined variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



pierozanetti wrote:
> Hi, 
> 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?

No, it is not 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?

There is an unbounded number of incorrect C++ programs.  We warn about
a subset of them.  Detecting every incorrect C++ program is, I'm sure
an uncomputable problem.

Andrew.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux