6

I was seeing this code

#include <stdio.h> main(t,_,a) char *a; { return!0<t?t<3?main(-79,-13,a+main(-87,1-_,main(-86,0,a+1)+a)): 1,t<_?main(t+1,_,a):3,main(-94,-27+t,a)&&t==2?_<13? main(2,_+1,"%s %d %d\n"):9:16:t<0?t<-72?main(_,t, "@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l+,/n{n+,/+#n+,/#\ ;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l \ q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# \ ){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' \ iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c \ ;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' ')#\ }'+}##(!!/") :t<-50?_==*a?putchar(31[a]):main(-65,_,a+1):main((*a=='/')+t,_,a+1) :0<t?main(2,2,"%s"):*a=='/'||main(0,main(-61,*a, "!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry"),a+1); } 

and I saw this _ main()

I never saw this sign in use and never read about anywhere,
what is it used for?

2

3 Answers 3

7

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.

Sign up to request clarification or add additional context in comments.

6 Comments

@MukulKumar Yes, exactly.
Why would it call main() ?
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.
I 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.
it prints a 12 stanza poem
|
3

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 _.

Comments

3

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.

2 Comments

quora.com/What-is-the-most-obfuscated-C-code-you-have-ever-seen ..... look at the 4Th answer(doughnut one)...it's amazing!!!
@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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.