Why does C/C++ programs crash

D

Default User

- said:
C/C++ Programs can crash because of poor coding.
A question which I would like to ask is (to you)...

What OS are you using?

Who are you talking to, and about what? Please quote the relevant
portion of the previous message. Google now does that automatically, so
you have little excuse.




Brian
 
J

Jakob Bieling

Default User said:
Jakob Bieling wrote:
Probably not. Which section mandates the compiler aborting?

I have not found any section that explicitly _mandates_ it. But I
did find those above sections about conversions. Now, maybe I did not
look at the right pages, but I could not find anything saying a
conversion from int to pointer (a pointer to int, specifically) was
legal, except for an int being 0 (simplified quote, see 4.10/1).

If the Standard does indeed not mention it anywhere, then I conclude
this is undefined behaviour. Thus, the compiler could silently ignore it
and not "abort with an error." On the other hand, you said a diagnostic
is required. Why?

regards
 
J

Jerry Coffin

[ ... ]
I have not found any section that explicitly _mandates_ it. But I
did find those above sections about conversions. Now, maybe I did not
look at the right pages, but I could not find anything saying a
conversion from int to pointer (a pointer to int, specifically) was
legal, except for an int being 0 (simplified quote, see 4.10/1).

If the Standard does indeed not mention it anywhere, then I conclude
this is undefined behaviour. Thus, the compiler could silently ignore it
and not "abort with an error." On the other hand, you said a diagnostic
is required. Why?

4/1: Standard conversions are implicit conversions defined for built-
in types. Clause 4 enumerates the full set of such conversions.

4/3: An expression e can be implicitly converted to a type T if and
only if the declaration “T t=e;” is well-formed, for some invented
temporary variable t (8.5).

1.4/1: The set of diagnosable rules consists of all syntactic and
semantic rules in this International Standard except for those rules
containing an explicit notation that “no diagnostic is required” or
which are described as resulting in “undefined behavior.”

1.4/2: If a program contains a violation of any diagnosable rule, a
conforming implementation shall issue at least one diagnostic
message...
 
D

Default User

Jakob said:
I have not found any section that explicitly mandates it.

That's right. The Standard has a number of situations and conditions
where it requires a diagnostic. I'm unaware of any section that
mandates that compilation stop.

A "diagnostic" can be almost anything the compiler desiger wants.
That's strictly QOI.




Brian
 
J

Jakob Bieling

Jerry Coffin said:
[ ... ]
I have not found any section that explicitly _mandates_ it. But I
did find those above sections about conversions. Now, maybe I did not
look at the right pages, but I could not find anything saying a
conversion from int to pointer (a pointer to int, specifically) was
legal, except for an int being 0 (simplified quote, see 4.10/1).

If the Standard does indeed not mention it anywhere, then I
conclude this is undefined behaviour. Thus, the compiler could
silently ignore it and not "abort with an error." On the other hand,
you said a diagnostic is required. Why?

4/1: Standard conversions are implicit conversions defined for built-
in types. Clause 4 enumerates the full set of such conversions.

4/3: An expression e can be implicitly converted to a type T if and
only if the declaration “T t=e;” is well-formed, for some invented
temporary variable t (8.5).

1.4/1: The set of diagnosable rules consists of all syntactic and
semantic rules in this International Standard except for those rules
containing an explicit notation that “no diagnostic is required” or
which are described as resulting in “undefined behavior.”

1.4/2: If a program contains a violation of any diagnosable rule, a
conforming implementation shall issue at least one diagnostic
message...

So in essence, the posted code snippet produces undefined behaviour
for which a diagnostic message is required?

regards
 
J

Jakob Bieling

Default User said:
Jakob Bieling wrote:
That's right. The Standard has a number of situations and conditions
where it requires a diagnostic. I'm unaware of any section that
mandates that compilation stop.

Yip, should have been more careful with my wording regarding the
compilation stop. My original reply was supposed to focus on the
undefinedness of that code snippet, which I see now you seem to agree
with.

regards
 
J

Jerry Coffin

[ ... ]
So in essence, the posted code snippet produces undefined behaviour
for which a diagnostic message is required?

No -- it is a ill-formed code for which a diagnostic is required.
 
M

Marcus Kwok

Robbie Hatley said:
That's like saying, "your car caught fire and burned up, Mr. Smith,
so we're sorry, but we can't pay on your claim; you're only insured
against actual CRASHES, not fires". In other words, it crashed.

It's more like saying, "Your car is still running but can only drive
around in circles. However, the car is still (nominally) driveable and
did not crash, so no claim for you."
That's like saying, "I'm sorry, but we can't pay on your claim
because you crashed your car while it was still inside the car
lot you bought it from." In other words, it crashed.

It's more like, "I'm sorry, but we can't pay on your claim because you
do not yet own the car." If a program doesn't compile, there is no
program that can crash.
The user slammed the door into the computer, or the HD engineer
designed a flaky product. In other words, dumb mistakes.

HDDs are mechanical devices, subject to the laws of thermodynamics.
There are no perpetual motion machines. All hard drives will eventually
fail. Of course, if you are "not dumb" enough to make a hard drive that
will never fail, you stand to make a lot of money :)
In other words, someone made a dumb mistake, and cosmic rays
seemed a good thing to blame. :)

Modern computers operate based on (magnetic) field effect transistors.
Occasionally a cosmic ray will have enough energy to alter the magnetic
field and spontaneously flip a bit somewhere in the computer.
 
R

Richard Herring

In message <[email protected]>, Marcus Kwok

[off-topic, but let's not propagate too many misconceptions...]
Modern computers operate based on (magnetic) field effect transistors.

What is a "magnetic field effect transistor"? The "field" in
"field-effect transistor" refers to the _electric_ field between gate
and channel.

http://en.wikipedia.org/wiki/Field_effect_transistor
Occasionally a cosmic ray will have enough energy to alter the magnetic
field and spontaneously flip a bit somewhere in the computer.
Dynamic memory operates by storing electric charge in a potential well.

http://en.wikipedia.org/wiki/Dynamic_RAM

Occasionally a cosmic ray neutron will induce a decay producing an alpha
particle and a couple of electrons, which can tip the balance of the
stored charge and cause a bit error.

http://en.wikipedia.org/wiki/Soft_error
 
M

Marcus Kwok

Richard Herring said:
In message <[email protected]>, Marcus Kwok

[off-topic, but let's not propagate too many misconceptions...]
Modern computers operate based on (magnetic) field effect transistors.

What is a "magnetic field effect transistor"? The "field" in
"field-effect transistor" refers to the _electric_ field between gate
and channel.

http://en.wikipedia.org/wiki/Field_effect_transistor
Occasionally a cosmic ray will have enough energy to alter the magnetic
field and spontaneously flip a bit somewhere in the computer.
Dynamic memory operates by storing electric charge in a potential well.

http://en.wikipedia.org/wiki/Dynamic_RAM

Occasionally a cosmic ray neutron will induce a decay producing an alpha
particle and a couple of electrons, which can tip the balance of the
stored charge and cause a bit error.

http://en.wikipedia.org/wiki/Soft_error

OK, thanks. This was written off the top of my head in a hurry, and
it's been a while since I had my microelectronics classes...
 
C

Christopher Hulbert

Marcus said:
Richard Herring said:
In message <[email protected]>, Marcus Kwok

[off-topic, but let's not propagate too many misconceptions...]
Modern computers operate based on (magnetic) field effect transistors.
What is a "magnetic field effect transistor"? The "field" in
"field-effect transistor" refers to the _electric_ field between gate
and channel.

<OT>
Although the FETs in computers are E-field based there are M-field based FETs

See:
http://www.physics.gatech.edu/people/faculty/ulandman/276_gurzhi_et_al2003_4.pdf
 
R

Richard Herring

Marcus said:
Richard Herring said:
In message <[email protected]>, Marcus Kwok

[off-topic, but let's not propagate too many misconceptions...]
Modern computers operate based on (magnetic) field effect transistors.
What is a "magnetic field effect transistor"? The "field" in
"field-effect transistor" refers to the _electric_ field between gate
and channel.

<OT>
Although the FETs in computers are E-field based there are M-field based FETs

See:
http://www.physics.gatech.edu/people/faculty/ulandman/276_gurzhi_et_al20
03_4.pdf

</OT>

<OT++> The word "proposed" features largely in that document ;-) </OT++>
 
C

Christopher Hulbert

Richard said:
In message said:
Marcus said:
In message <[email protected]>, Marcus Kwok

[off-topic, but let's not propagate too many misconceptions...]
Modern computers operate based on (magnetic) field effect transistors.
What is a "magnetic field effect transistor"? The "field" in
"field-effect transistor" refers to the _electric_ field between gate
and channel.

<OT>
Although the FETs in computers are E-field based there are M-field
based FETs

See:
http://www.physics.gatech.edu/people/faculty/ulandman/276_gurzhi_et_al20
03_4.pdf

</OT>

<OT++> The word "proposed" features largely in that document ;-) </OT++>

Yes, I guess I should have said "there is MFET research" where research is the
keyword. Until this thread I don't think I've ever even heard of MFETs even in
concept!
 
M

Marcus Kwok

Christopher Hulbert said:
Yes, I guess I should have said "there is MFET research" where research is the
keyword. Until this thread I don't think I've ever even heard of MFETs even in
concept!

Maybe I'm just ahead of the curve :)

OK, I think that's enough of this OT stuff. Sorry for the digression...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,170
Latest member
Andrew1609
Top