4

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?

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
Mukul Kumar
  • 315
  • 1
  • 5
  • 16
  • 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 Answers3

6

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.

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
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 _.

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
odisseas
  • 31
  • 2
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.

Community
  • 1
  • 1
chqrlie
  • 131,814
  • 10
  • 121
  • 189
  • 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