The number “195” is the code of RET instruction on x86.
The C++ compiler (gcc in my case) is unable to recognize that “main” wasn’t declared as a function. The compiler only sees that there is the “main” symbol, and presumes that it refers to a function.
The C++ code
int main = ( cout << "Hello world!\n", 195 );
is initializing a variable at file-scope. This initialization code is executed before the C/C++ environment calls main(), but after it initializes the “cout” variable. The initialization prints “Hello, world!\n”, and sets the value of variable “main” to 195. After all initialization is done, the C/C++ environment makes a call to “main”. The program returns immediately from this call because we put a RET instruction (code 195) at the address of “main”.
Sample GDB output:
$ gdb ./a
(gdb) break _fini
Breakpoint 1 at 0x8048704
(gdb) print main
$1 = 0
(gdb) disass &main
Dump of assembler code for function main:
0x0804a0b4 <+0>: add %al,(%eax)
0x0804a0b6 <+2>: add %al,(%eax)
End of assembler dump.
(gdb) run
Starting program: /home/atom/a
Hello world!
Breakpoint 1, 0x08048704 in _fini ()
(gdb) print main
$2 = 195
(gdb) disass &main
Dump of assembler code for function main:
0x0804a0b4 <+0>: ret
0x0804a0b5 <+1>: add %al,(%eax)
0x0804a0b7 <+3>: add %al,(%eax)
End of assembler dump.