Reading as a god
Chapter 196 IOCCC
Chapter 196 IOCCC
Zhang Shan noticed a strange contest mentioned in "Programming for C Experts" - the International Confused Code Contest of C Language.
When I went out, I turned right and Du Niang said:
The International Obfuscated C Code Contest (IOCCC, The International Obfuscated C Code Contest) is an international programming competition that has been held annually since 1984 (with the exception of 1997, 1999, 2002, 2003 and 2006).The purpose is to write the most creative and most difficult to understand C language code.
Zhang Shan: Σ(っ°Д°;)っ
There is actually such a game?And it's an international programming competition? ? ?
IOCCC was started by Landon Curt Noll and Larry Bassel in 1984 when they were employed by National Semiconductor's Genix programming group.The idea for the contest came when the two of them compared each other's notes about some poorly written code they had to fix.
Every year, the IOCCC competition rules are posted on its website.The rules vary from year to year and are accompanied by a set of guidelines that attempt to express the spirit of the rules.
These rules are often written on purpose, with neat loopholes that contestants are encouraged to discover and abuse.
Tsk, although it doesn't sound very popular, but Zhang Shan thinks it is necessary to participate in it!
It's very interesting~
The book is not all interesting things, some things are very heavy!
In the book "C Expert Programming", Zhang Shan saw such an example:
"In the spring of 1993, in SunSoft's operating system development group, we (the authors of "Programming with C Experts") received a "Priority [-]" bug report about a problem with the asynchronous I/O library.
If this bug is not resolved, it will kill a $2000 million hardware product business because the other party needs to use the functions of this library.So, we were under pressure to find this bug.After several intense debugging, the problem was fixed on the following statement:
x == 2;
This is a typo, it meant an assignment statement.The programmer put his finger on the "=" key and accidentally pressed it more.
This statement becomes to compare x with 2, the comparison result is true or false, and then discard the comparison result. "
Zhang Shan was filled with emotion after seeing this bug incident!
Although the author of "C Expert Programming" is talking to himself, Zhang Shan also feels the same way.
Accidentally typed an extra equal sign, just trembling hands~
Who can 100% guarantee that similar mistakes will not be made!
Speaking of "=" and "==", although the two seem to be indistinguishable, they are completely different symbols in the C language!
In the C language, the most confusing operators are "=" and "==".
Among them, "=" is not equal to a symbol, but an assignment operator, such as x=3, which means assigning 3 to x.
Compared with the assignment operator with only one equal sign, the equal operator in relational operators is represented by two equal signs "==".
Because of this, it leads to a potential problem: Out of habit, we may often write assignment operators where we need an equal operator.
Or accidentally type an extra "=" in the place where the assignment operator needs to be written
I have to say that the expressive ability of the C language is really strong. According to the situation described in the book "C Programming Expert", the compiler can accept the statement "finding the value of an expression, but not using the value". , and do not issue any warnings, and simply discard the return result.
And this kind of problem will not report an error in the actual compilation.
Just be careful and careful!
It sounds like the example mentioned in the book is a relatively "gentle mistake". Some accidents related to computer errors are life-threatening at every turn.
Zhang Shan has heard professors from the Department of Computer Science say more than once:
During the first Gulf War in February 1991, a Scud missile launched by Iraq accurately hit the U.S. base in Dhahran, Saudi Arabia, killing 2 U.S. soldiers on the spot and injuring more than 28 others. The only loss in the Gulf War with more than a hundred casualties.
It was later discovered that a simple computer bug disabled the base's Patriot anti-missile system, which failed to intercept the Scud missile in the air.At that time, the Patriot anti-missile system responsible for defending the base had been working continuously for 100 hours. Every hour of work, the clock in the system would have a tiny millisecond delay, which was the root cause of the failure tragedy.The clock register of the Patriot anti-missile system is designed to be 24 bits, so the accuracy of time is limited to 24 bits.After working for a long time, this small precision error is gradually magnified.After 100 hours of work, the system time lag is one-third of a second.
For the average person, 0.33 seconds is insignificant.But for a radar system that needs to track and destroy an airborne missile, it's disastrous - the Hussein Scud missile travels at Mach 4.2 (1.5 kilometers per second), and this "mean" 0.33 seconds equates to about 600 meters error.In the case of the Dhahran missile, radar detected the missile in the air, but the base's anti-missiles did not launch because of a clock error that was not able to accurately track it.
Similar accidents include the Ariane rocket incident in June 1996.
When programming, the programmer must define the variables used by the program and the computer memory required by these variables. These memories are defined by bits. A 16-bit variable can represent a value between -32 and 768 (this value The origin is 32^767-2).
A 64-bit variable can represent values between 9.223.372.036.854.775.808 and 9.223.372.036.854.775.807.
On June 1996, 6, after the first launch of the Ariane 4 carrier rocket ignited, the rocket began to deviate from the course and was eventually forced to detonate and self-destruct. The whole process only took 5 seconds.
The Ariane 5 launch vehicle is based on the previous generation 4 rocket.In the Type 4 rocket system, a 16-bit variable and memory is used for the measurement value of a horizontal velocity, because it has been repeatedly verified in the Type 4 rocket system that this value will not exceed the 16-bit variable, while the Type 5 rocket The developer simply copied this part of the program without numerically verifying the new rocket, resulting in a fatal numerical overflow.
After the launch, this 64-bit variable with a decimal point was converted into a 16-bit variable without a decimal point, which caused a series of errors, which affected all the computers and hardware on the rocket, paralyzed the entire system, and had to choose to self-destruct. $4 million turned into a huge firework.
It's all over!
In addition to emotion, Zhang Shan made the settlement in the system in time:
Speaking of which, although Zhang Shan reads very quickly, it still took him 3 hours to finish this book!
"Ding~ The host studied for 3 hour in total, gained a total of 21600 yuan in money, and a total of 43200 experience points (including the bonus of the No. [-] badge)"
"In addition, the host read a total of 43 words, and earned a total of 43 soft sister coins~"
"The current system level is level 12, and the experience required to upgrade is 7/097"
(End of this chapter)
Zhang Shan noticed a strange contest mentioned in "Programming for C Experts" - the International Confused Code Contest of C Language.
When I went out, I turned right and Du Niang said:
The International Obfuscated C Code Contest (IOCCC, The International Obfuscated C Code Contest) is an international programming competition that has been held annually since 1984 (with the exception of 1997, 1999, 2002, 2003 and 2006).The purpose is to write the most creative and most difficult to understand C language code.
Zhang Shan: Σ(っ°Д°;)っ
There is actually such a game?And it's an international programming competition? ? ?
IOCCC was started by Landon Curt Noll and Larry Bassel in 1984 when they were employed by National Semiconductor's Genix programming group.The idea for the contest came when the two of them compared each other's notes about some poorly written code they had to fix.
Every year, the IOCCC competition rules are posted on its website.The rules vary from year to year and are accompanied by a set of guidelines that attempt to express the spirit of the rules.
These rules are often written on purpose, with neat loopholes that contestants are encouraged to discover and abuse.
Tsk, although it doesn't sound very popular, but Zhang Shan thinks it is necessary to participate in it!
It's very interesting~
The book is not all interesting things, some things are very heavy!
In the book "C Expert Programming", Zhang Shan saw such an example:
"In the spring of 1993, in SunSoft's operating system development group, we (the authors of "Programming with C Experts") received a "Priority [-]" bug report about a problem with the asynchronous I/O library.
If this bug is not resolved, it will kill a $2000 million hardware product business because the other party needs to use the functions of this library.So, we were under pressure to find this bug.After several intense debugging, the problem was fixed on the following statement:
x == 2;
This is a typo, it meant an assignment statement.The programmer put his finger on the "=" key and accidentally pressed it more.
This statement becomes to compare x with 2, the comparison result is true or false, and then discard the comparison result. "
Zhang Shan was filled with emotion after seeing this bug incident!
Although the author of "C Expert Programming" is talking to himself, Zhang Shan also feels the same way.
Accidentally typed an extra equal sign, just trembling hands~
Who can 100% guarantee that similar mistakes will not be made!
Speaking of "=" and "==", although the two seem to be indistinguishable, they are completely different symbols in the C language!
In the C language, the most confusing operators are "=" and "==".
Among them, "=" is not equal to a symbol, but an assignment operator, such as x=3, which means assigning 3 to x.
Compared with the assignment operator with only one equal sign, the equal operator in relational operators is represented by two equal signs "==".
Because of this, it leads to a potential problem: Out of habit, we may often write assignment operators where we need an equal operator.
Or accidentally type an extra "=" in the place where the assignment operator needs to be written
I have to say that the expressive ability of the C language is really strong. According to the situation described in the book "C Programming Expert", the compiler can accept the statement "finding the value of an expression, but not using the value". , and do not issue any warnings, and simply discard the return result.
And this kind of problem will not report an error in the actual compilation.
Just be careful and careful!
It sounds like the example mentioned in the book is a relatively "gentle mistake". Some accidents related to computer errors are life-threatening at every turn.
Zhang Shan has heard professors from the Department of Computer Science say more than once:
During the first Gulf War in February 1991, a Scud missile launched by Iraq accurately hit the U.S. base in Dhahran, Saudi Arabia, killing 2 U.S. soldiers on the spot and injuring more than 28 others. The only loss in the Gulf War with more than a hundred casualties.
It was later discovered that a simple computer bug disabled the base's Patriot anti-missile system, which failed to intercept the Scud missile in the air.At that time, the Patriot anti-missile system responsible for defending the base had been working continuously for 100 hours. Every hour of work, the clock in the system would have a tiny millisecond delay, which was the root cause of the failure tragedy.The clock register of the Patriot anti-missile system is designed to be 24 bits, so the accuracy of time is limited to 24 bits.After working for a long time, this small precision error is gradually magnified.After 100 hours of work, the system time lag is one-third of a second.
For the average person, 0.33 seconds is insignificant.But for a radar system that needs to track and destroy an airborne missile, it's disastrous - the Hussein Scud missile travels at Mach 4.2 (1.5 kilometers per second), and this "mean" 0.33 seconds equates to about 600 meters error.In the case of the Dhahran missile, radar detected the missile in the air, but the base's anti-missiles did not launch because of a clock error that was not able to accurately track it.
Similar accidents include the Ariane rocket incident in June 1996.
When programming, the programmer must define the variables used by the program and the computer memory required by these variables. These memories are defined by bits. A 16-bit variable can represent a value between -32 and 768 (this value The origin is 32^767-2).
A 64-bit variable can represent values between 9.223.372.036.854.775.808 and 9.223.372.036.854.775.807.
On June 1996, 6, after the first launch of the Ariane 4 carrier rocket ignited, the rocket began to deviate from the course and was eventually forced to detonate and self-destruct. The whole process only took 5 seconds.
The Ariane 5 launch vehicle is based on the previous generation 4 rocket.In the Type 4 rocket system, a 16-bit variable and memory is used for the measurement value of a horizontal velocity, because it has been repeatedly verified in the Type 4 rocket system that this value will not exceed the 16-bit variable, while the Type 5 rocket The developer simply copied this part of the program without numerically verifying the new rocket, resulting in a fatal numerical overflow.
After the launch, this 64-bit variable with a decimal point was converted into a 16-bit variable without a decimal point, which caused a series of errors, which affected all the computers and hardware on the rocket, paralyzed the entire system, and had to choose to self-destruct. $4 million turned into a huge firework.
It's all over!
In addition to emotion, Zhang Shan made the settlement in the system in time:
Speaking of which, although Zhang Shan reads very quickly, it still took him 3 hours to finish this book!
"Ding~ The host studied for 3 hour in total, gained a total of 21600 yuan in money, and a total of 43200 experience points (including the bonus of the No. [-] badge)"
"In addition, the host read a total of 43 words, and earned a total of 43 soft sister coins~"
"The current system level is level 12, and the experience required to upgrade is 7/097"
(End of this chapter)
You'll Also Like
-
The end of the world is coming, I became a card maker
Chapter 225 8 hours ago -
I was trying to survive in the community, but I was pulled into the management group
Chapter 212 8 hours ago -
Dragon Ball: Soul from another world, disk of luck!
Chapter 179 8 hours ago -
Pokémon: Dark King
Chapter 219 8 hours ago -
Super Rich: Compensation for failure is 10,000 times
Chapter 247 8 hours ago -
Discussion: How the Nine-Tails led Naruto astray
Chapter 215 8 hours ago -
City: Cultivating Immortals for a Thousand Years, Returning to Be a Dad
Chapter 305 8 hours ago -
Naruto: The opening scene rebukes Danzo and the Yin-Yang Third Generation
Chapter 215 8 hours ago -
Kiana's Journey to All Worlds
Chapter 60 8 hours ago -
Infinite Apocalypse: Super cheats every time you sign in!
Chapter 246 8 hours ago