Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

Optimized C code

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());
}

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.

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");}

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());}

Name: Anonymous 2007-05-10 12:01 ID:yEu975o6

__attribute__((noreturn))

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?

Name: Anonymous 2007-05-10 12:40 ID:Heaven

wtf does >>4 do?

Name: Anonymous 2007-05-10 13:22 ID:Heaven

>>7
Exactly what the code says it does?

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)

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.

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"?

Name: Anonymous 2007-05-10 14:19 ID:Heaven

>>9
pthread errors out, it's not the program itself. What's your point?

Name: Anonymous 2007-05-10 14:33 ID:Heaven

>>12
Fifanit lafeli.

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();
        }
}

Name: Anonymous 2007-05-10 16:40 ID:Heaven

>>14
That's pretty sandcore.

Name: Anonymous 2007-05-11 15:55 ID:ucSDTBk2

Name: Anonymous 2007-05-11 16:50 ID:8EN0NJ9e

>>14
I lol'd especially at @author

Name: Anonymous 2007-05-11 17:25 ID:Wd9oB0OY

True EXPERT PROGRAMMERS don't write comments. Certainly not doc-comments.

Name: Anonymous 2007-05-11 18:16 ID:CQNIjGkI

>>18
True. Job security and all that.

Name: Anonymous 2007-05-11 18:20 ID:trI/QcLL

main()
{
__asm push main
__asm ret
}

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.

Name: Anonymous 2007-05-11 22:03 ID:K6bJ/nys

A SUPERIOR SOLUTION FOR A SUPERIOR LANGUAGE:
(let main () (main))

Name: Anonymous 2007-05-12 4:09 ID:Heaven

This will do.

module Main where

main :: IO ()
main = main

Name: Anonymous 2007-05-12 5:39 ID:0PO4a/sD

main = lambda: main()
main()

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

Name: Anonymous 2007-05-12 14:19 ID:8wEikczw

:(){ :|:& };:

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();
    }
}

Name: Anonymous 2007-05-12 16:22 ID:3bShG9RE

>>27
LOL TELL ME YOU ARE A TROLL.

Name: Anonymous 2007-05-12 17:04 ID:GrELzOcm

>>26
Someone actually tricked 420chan's admin to run that. Lulz followed.

Name: Anonymous 2007-05-12 17:28 ID:+Njzwxvb

>>29
wutsit do?

Name: Anonymous 2007-05-12 17:34 ID:Heaven

>>30
CLASSIC FORK BOMB

LURK THE FUCK MOAR

Name: Anonymous 2007-05-14 0:06 ID:w3TIZ2xq

perl -e "fork while fork"

Name: Anonymous 2007-05-14 10:14 ID:fiOvqY26

9 ON ERROR GOTO 11
10 GOSUB 10
11 RESUME NEXT

Name: Anonymous 2007-05-16 0:17 ID:HqV4Y8o2

.(){.|.&};.

Name: Anonymous 2007-05-16 22:37 ID:tshMf42P

>> :(){ :|:& };:

WHAT IS THIS?>

Name: Anonymous 2007-05-16 23:01 ID:bgo0CyAN

>>35
It's a fork bomb for bash

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

Name: Anonymous 2007-05-17 3:04 ID:TgleNoyE

[code]
BOMB   JSR BOMB   ;BOMB MYSELF


Name: Anonymous 2007-05-17 3:41 ID:Heaven

+[Y+]

Name: Anonymous 2007-05-17 4:21 ID:beQsKz8y


  /=&\
$!\&=/

Name: Anonymous 2007-05-17 10:22 ID:kLRZ6ruN

bomb    dat    #0
dwarf    add    #4,bomb
    mov    bomb,@bomb
    jmp    dwarf
    end    dwarf

Name: Anonymous 2007-05-17 11:00 ID:Heaven

     ,-*
--≡(_)

Name: anonymous !faggot0tBQ 2007-05-17 11:29 ID:Heaven

oh shi-

Name: Anonymous 2007-05-17 17:55 ID:0mMGE61v

>>1
I'll optimize it with tail call elimination:

10 GOTO 10 'LOL

Name: Anonymous 2007-05-17 20:12 ID:giWGiyAh

:s
start %0
goto s

Name: Anonymous 2007-05-17 20:40 ID:giWGiyAh

:s
start %0
goto s

Name: Anonymous 2007-05-18 5:35 ID:mNUBOItb

>>45-46
Please perform duplicate code elimination

Name: Anonymous 2009-01-14 12:27

LISP

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.

Name: Anonymous 2010-11-02 11:25

Name: Anonymous 2011-02-03 1:51

Name: Sgt.Kabu뇉颜kiman⬴讱 2012-05-29 1:33

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List