Optimized C code
1
Name:
Anonymous
2007-05-10 9:02
ID:YpMhiddP
Dear /prog/, how can I further optimize this piece of code to make it ENTERPRISE ? :
int main(void){
return(main());
}
2
Name:
Anonymous
2007-05-10 9:19
ID:wv/ChYCT
Blowing the stack of one process is not ENTERPRISE enough.
int main(void){
while(1){fork();}
}
If I was an EXPERT PROGRAMMER I'd rewrite this in Java, but I have no idea how to start a new process (not thread) with Sun's libraries.
3
Name:
Anonymous
2007-05-10 9:23
ID:Heaven
>>1
IT NEVER REACHES return YOU FAG, THEREFORE RETURN IS A WASTE OF SPACE.
OPTIMIZED CODE:
main(){_asm_ _volitate_("OPTIMIZED CODE IS OPTIMIZED");}
4
Name:
Anonymous
2007-05-10 10:42
ID:XZvi4Ty8
#include <pthread.h>
#include <unistd.h>
main(){for(pthread_t t;!pthread_create(&t,NULL,*main,NULL);fork());}
5
Name:
Anonymous
2007-05-10 12:01
ID:yEu975o6
__attribute__((noreturn))
6
Name:
Anonymous
2007-05-10 12:07
ID:sRYuHWkv
.file "main.c"
.def ___main; .scl 2; .type 32; .endef
.text
.p2align 4,,15
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
pushl %ebp
movl $16, %eax
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
call __alloca
L2:
call ___main
call ___main
jmp L2
what's with ___main calls?
7
Name:
Anonymous
2007-05-10 12:40
ID:Heaven
8
Name:
Anonymous
2007-05-10 13:22
ID:Heaven
>>7
Exactly what the code says it does?
9
Name:
Anonymous
2007-05-10 13:31
ID:Heaven
>>8
from looking at the code i wouldn't think it would output anything, but apparently it does...
$ ./a.out
Fatal error 'mutex is on list' at lineF a5tal4 F0eF rairtoaln ref rirl'oemutex is on listr '/usr/src/lib/libpthread/thread/thr_mutex.c '(a_pq_insert_tail: Already in priority queueet 'rl rianntoe l=5i 4n00e)
i20n0F Fifanit lafeli l/usr/src/lib/libpthread/thread/thr_mutex.cee r (er/usr/src/lib/libpthread/thread/thr_priority_queue.cr rno(o re= r 'r0_pq_insert_tail: Already in priority queuen)'o
a=t 0l)i
ne 200 in file /usr/src/lib/libpthread/thread/thr_priority_queue.c (errno = 0)
Fatal error 'mutex is on list' at line 540 in file /usr/src/lib/libpthread/thread/thr_mutex.c (errno = 0)
10
Name:
Anonymous
2007-05-10 14:03
ID:cAqpBeR/
>>1
This recursive approach, while elegant, is inefficient in C.
Use a language that has tail call optimization.
11
Name:
Anonymous
2007-05-10 14:10
ID:P9SShx0H
>>10
What does this have to do with the topic, or is this just your way to say "I have to read my SICP a bit more closely"?
12
Name:
Anonymous
2007-05-10 14:19
ID:Heaven
>>9
pthread errors out, it's not the program itself. What's your point?
13
Name:
Anonymous
2007-05-10 14:33
ID:Heaven
14
Name:
Anonymous
2007-05-10 16:31
ID:X7YGl5To
import java.lang.Thread;
/**
* @author EXPERT PROGRAMMER
*/
class ExtraOptimizedClass {
public static void main(String[] args) {
new ExtraOptimizedClass();
}
public ExtraOptimizedClass() {
class ExtraOptimizedThread extends Thread {
public ExtraOptimizedThread() { }
public void run() {
while ((new Boolean(true)).booleanValue()) new ExtraOptimizedClass();
}
}
ExtraOptimizedThread expertThread = new ExtraOptimizedThread();
expertThread.start();
}
}
15
Name:
Anonymous
2007-05-10 16:40
ID:Heaven
>>14
That's pretty sandcore.
16
Name:
Anonymous
2007-05-11 15:55
ID:ucSDTBk2
17
Name:
Anonymous
2007-05-11 16:50
ID:8EN0NJ9e
>>14
I lol'd especially at @author
18
Name:
Anonymous
2007-05-11 17:25
ID:Wd9oB0OY
True EXPERT PROGRAMMERS don't write comments. Certainly not doc-comments.
19
Name:
Anonymous
2007-05-11 18:16
ID:CQNIjGkI
>>18
True. Job security and all that.
20
Name:
Anonymous
2007-05-11 18:20
ID:trI/QcLL
main()
{
__asm push main
__asm ret
}
21
Name:
Anonymous
2007-05-11 21:04
ID:mMvukwPl
>>20
Still gonna smash the stack due to main()'s "push ebp; mov ebp, esp" minimal prelude.
22
Name:
Anonymous
2007-05-11 22:03
ID:K6bJ/nys
A SUPERIOR SOLUTION FOR A SUPERIOR LANGUAGE:
(let main () (main))
23
Name:
Anonymous
2007-05-12 4:09
ID:Heaven
This will do.
module Main where
main :: IO ()
main = main
24
Name:
Anonymous
2007-05-12 5:39
ID:0PO4a/sD
main = lambda: main()
main()
25
Name:
Anonymous
2007-05-12 6:29
ID:osle3kGZ
*Main> :t compute
compute :: forall a. Int -> IO a -> IO (Maybe a)
*Main> let loop = loop in compute (10^5) loop
Nothing
it :: Maybe Integer
(0.02 secs, 2569484 bytes)
SUPERIOR
26
Name:
Anonymous
2007-05-12 14:19
ID:8wEikczw
:(){ :|:& };:
27
Name:
Anonymous
2007-05-12 16:16
ID:Heaven
None of you are checking whether 'main' exists before calling it. You never know, it could be a NULL pointer and cause the whole program to crash.
[code]
int main(void) {
while (fork()) {
assert(main != NULL);
main();
}
}
28
Name:
Anonymous
2007-05-12 16:22
ID:3bShG9RE
>>27
LOL TELL ME YOU ARE A TROLL.
29
Name:
Anonymous
2007-05-12 17:04
ID:GrELzOcm
>>26
Someone actually tricked 420chan's admin to run that. Lulz followed.
30
Name:
Anonymous
2007-05-12 17:28
ID:+Njzwxvb
31
Name:
Anonymous
2007-05-12 17:34
ID:Heaven
>>30
CLASSIC FORK BOMB
LURK THE FUCK MOAR
32
Name:
Anonymous
2007-05-14 0:06
ID:w3TIZ2xq
perl -e "fork while fork"
33
Name:
Anonymous
2007-05-14 10:14
ID:fiOvqY26
9 ON ERROR GOTO 11
10 GOSUB 10
11 RESUME NEXT
34
Name:
Anonymous
2007-05-16 0:17
ID:HqV4Y8o2
.(){.|.&};.
35
Name:
Anonymous
2007-05-16 22:37
ID:tshMf42P
>> :(){ :|:& };:
WHAT IS THIS?>
36
Name:
Anonymous
2007-05-16 23:01
ID:bgo0CyAN
>>35
It's a fork bomb for bash
37
Name:
Anonymous
2007-05-16 23:45
ID:wZP2Tx36
>>35
#!/usr/bin/bash
forkbomb()
{
# call forkbomb, pipe to itself (hence forking itself), place in background
forkbomb | forkbomb &
}
# set of fork bomb
forkbomb
38
Name:
Anonymous
2007-05-17 3:04
ID:TgleNoyE
[code]
BOMB JSR BOMB ;BOMB MYSELF
39
Name:
Anonymous
2007-05-17 3:41
ID:Heaven
+[Y+]
40
Name:
Anonymous
2007-05-17 4:21
ID:beQsKz8y
/=&\
$!\&=/
41
Name:
Anonymous
2007-05-17 10:22
ID:kLRZ6ruN
bomb dat #0
dwarf add #4,bomb
mov bomb,@bomb
jmp dwarf
end dwarf
42
Name:
Anonymous
2007-05-17 11:00
ID:Heaven
,-*
--≡(_)
43
Name:
anonymous
!faggot0tBQ
2007-05-17 11:29
ID:Heaven
oh shi-
44
Name:
Anonymous
2007-05-17 17:55
ID:0mMGE61v
>>1
I'll optimize it with tail call elimination:
10 GOTO 10 'LOL
45
Name:
Anonymous
2007-05-17 20:12
ID:giWGiyAh
:s
start %0
goto s
46
Name:
Anonymous
2007-05-17 20:40
ID:giWGiyAh
:s
start %0
goto s
47
Name:
Anonymous
2007-05-18 5:35
ID:mNUBOItb
>>45-46
Please perform duplicate code elimination
48
Name:
Anonymous
2009-01-14 12:27
LISP
49
Name:
Anonymous
2009-03-06 10:41
The method is supposed to belong to as well as per example reddit About reddit I have posted my previous thoughts here.
50
Name:
Anonymous
2010-11-02 11:25