I was seeing this code and I saw this _ sign(inside main())...
I never saw this sign in use and never read about anywhere,
what is it used for?
- 38,744
- 8
- 68
- 123
- 325
- 4
- 15
-
It's difficult to understand the code as it's obfuscated. – kiner_shah Dec 04 '16 at 11:36
-
Possible duplicate of [What is the reason for underscore in C variable name definition?](https://stackoverflow.com/questions/8093336/what-is-the-reason-for-underscore-in-c-variable-name-definition) – jww Oct 18 '17 at 03:28
3 Answers
It's just an identifier, it's valid. You can use _ by itself as an identifier.
For example you can do this
int _;
that makes _ a variable of type int.
The code though, exposes a fundamental problem because it calls main() from within the program. Doing so, invokes undefined behavior.
- 52,066
- 5
- 58
- 95
-
-
-
Read the code carefully, it is calling `main()` from within `main()` itself. Also, the signature for `main()` is not standard. That program, would have a specific behavior in a specific compiler and platform I suppose. – Iharob Al Asimi Dec 04 '16 at 11:45
-
1I don't really see the point of, obfuscated programming or whatever it's name is. Some people might think they are very smart because they write such programs, I think it's idiotic. Please note, that I do not intend to offend anyone who likes this, I am just expressing my opinion. – Iharob Al Asimi Dec 04 '16 at 11:48
-
@MukulKumar No thank you, I don't trust it because I can't quickly understand what it does. – Iharob Al Asimi Dec 04 '16 at 11:50
-
1
The underscore is one of the characters allowed in the names of variables and functions in C. It's not commonly used, especially at the begin or end of names. For this reason, so it's sometimes useful for:
- Defining a variable name in a library that is not likely to clash with another name in the same scope;
- Writing confusing code.
Your example uses it in the second version, for example by defining a variable simply called _.
- 52,066
- 5
- 58
- 95
- 31
- 2
You are looking at an example of C code obfuscation.
The programmer uses a single underscore _ as the name for the second argument to the main function.
He uses an old style declaration for main() somewhat equivalent to modern int main(int t, int _, char *a).
This prototype for main is invalid per all versions of the C Standard, but may function on some systems and the main function actually calls itself recursively with arguments of the expected types. The program can tell if it is the main invocation by testing if t > 0. This is not portable as arguments may be passed differently for different prototypes.
Obfuscated C is a game for advanced C programmers that can reach amazing levels of sophistication.
There is a world wide competition: The International Obfuscated C Code Contest.
Many world class programmers have spent countless hours polishing amazing code gems, including a compiler for a subset of C by Fabrice Bellard that can compile itself.
There is another game for aimless programmers: code golfing. The goal is to produce the smallest program to solve a given problem. Stack Exchange has a full site dedicated to this activity: https://codegolf.stackexchange.com/ . More wasted hours for fun and pleasure.
-
https://www.quora.com/What-is-the-most-obfuscated-C-code-you-have-ever-seen ..... look at the 4Th answer(doughnut one)...it's amazing!!! – Mukul Kumar Dec 04 '16 at 12:59
-
@MukulKumar: cute indeed, the first is suboptimal: `count` is unused and the `main` prototype could be made standard conformant at very little cost. Thanks for the link. – chqrlie Dec 04 '16 at 13:18