'짤림방지'에 해당되는 글 1건

  1. 2009.02.04 짤림방지용코드 by sloth_chord

/*
    짤림방지용 코드 조각들임
    출처는 책, 인터넷 등임
*/


void mem_able(void)
{
    int mega_byte = 0;

    while(malloc(1 << 20))
        mega_byte++;

    printf("%d mega bytes alloc\n", mega_byte);
}


void endian(void)
{
    int n = 1;

    char *ptr = (char*)&n;

    ((*ptr) == 1) ? puts("little endian") : puts("big endian");
}

char c;

void c_or_cpp(void)
{
    struct c
    {
        int arr[10];
    };

    size_t size = sizeof(c);

    printf("c%s\n", (size == sizeof(char)) ? "" : "++");
}

int is_power_of_two(unsigned n)

    return ( (n > 0) && !(n & (n - 1)) );
}



int is_odd(unsigned n)
{
    return (int)(n & 0x01);
}


#define offset(ds_p, field) ((size_t)&((ds_p)NULL) -> field)

#define CSA(h, l, a, b, c) {unsigned u = (a) ^ (b); unsigned v = (c); (h) = ((a) & (b)) | (u & v); (l) = u ^ v;}

quine 코드들....................

Scheme :

((lambda (x) (list x (list 'quote x))) '(lambda (x) (list x (list 'quote x))))

Python :

a = ['print "a =", a', 'for s in a: print s']
print "a =", a
for s in a: print s


Ruby :

def x(s); puts %Q{#{s} x(%q{#{s}})}; end; x(%q{def x(s); puts %Q{#{s} x(%q{#{s}})}; end;})





Posted by sloth_chord

댓글을 달아 주세요