OBFUSCATED C
Author: Robert Murray
Translator: Yuan Xiakai
Email - ccplusplus@21cn.com
Translation
After I see this topic, I want to try to write its output. The result is the same as I wrote, but I am not happy, but a confusion. Because I don't know how to use my limited C knowledge to explain why, I just guess, sad! But after reading the conclusion, everything is so simple, so clear. This article, let more people eliminate this damages. But I have limited horizon, and the translation is not good, and it is also calcined. Please don't laugh, please criticize.
text
Here are this confusing C program:
#include
Using namespace std;
Struct C;
Struct d {
Void Operator * (d) {cout << "one / n";
} C;
Struct e {
Void Operator * (e) {cout << "two / n";
} F;
Struct f;
Int main () {
C * C;
F * f;
Return 0;
}
The relationship between this problem is the meaning of the two statements in the main function main. According to C grammar, it seems that it is to define two pointers. That space is the culprit, it is very easy to make this misunderstanding. Name (C OR F) is also declared as class name and object name in the same scope (global), in which case the object name will block the name. A clear type must be used when using class names (such as Struct C * C;). Note [1]
Therefore, each statement in the letter main is a call of two yuan Operator *. It has the same effect as the following prices:
Int main () {
C.Operator * (c); // invokes d :: operator * (d)
F.Operator * (f); // invokes E :: Operator * (e)
Return 0;
}
The program output is:
One
Two
This is a confusing reason, dear C friends!
Author's post-talk:
This is my last "Obfuscated C " Column. I've been writing this column for a bit over 11 years now, ever since the first issue of C Report was published in January 1989. C has grown over the years, as have I, And My Life Has Taken Me In Other Directions. C Is No Longer a Part of What I do, So it's time to put this column to bed. I've had theplented people over the years; you Know who you are. Thanks for the ride, I'll never forget it!
Note:
1.The Class Name Can Only Be Invoked Using An Elaborated Type Specifier (E.G. Struct C * C;,). About the Author
As Red Sky's Chief Technology Officer, Rob Murray is responsible for tracking and evaluating current and new Internet technologies. These technologies provide the "plumbing" that is critical to Web-based solutions that are full-featured, robust and fast. "Focus is key , "he says." New tools appear on the market every day. We identify and adopt those technologies that are the very best match for our skills and our customers' needs. Most do not make the cut. "Before stepping into the CTO role, Mr. Murray was the Director of Systems Development for the Irvine office of Nuforia, where he was responsible for all fulfillment work in that office. An industry veteran, Mr. Murray spent the first 14 years of his career at AT & T Bell Laboratories, where he worked on object-oriented software and tools, including the first publicly released C compiler. He was the founding editor of the C Report in 1988, and has been a regular contributor to this respected trade magazine. Mr. Murray has been a prep ublication reviewer for many technical textbooks, including important works by C inventor Bjarne Stroustrup and Java inventor James Gosling. His own book, C Strategies and Tactics (Addison-Wesley 1993), is currently in its seventh printing and has been translated into French and Japanese .? His mission statement "I have to keep three sets of people happy:. my customers (who pay the bills); my employees and co-workers (who make successful projects happen); and my bosses (who sign my paycheck) One Of the nice thing.