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

The C Programming Language

Name: Anonymous 2011-10-24 21:45

Let's have a thread for the C programming language. It's an excellent language.

Name: Anonymous 2011-10-26 16:04

>>40
Fuck you GC faggot

>>39
Depends on situation (like always).

Name: Anonymous 2011-10-26 17:01

>>41
fuck off and die antiGC autist

Name: Anonymous 2011-10-27 17:15

Name: Anonymous 2011-10-27 17:20

>>43
ENTERPRISE QUALITY TROLLING!!!!

Name: Anonymous 2011-10-27 22:17

>>43
The buffoon who wrote that should really meditate over the ooc source code.

Name: Anonymous 2011-10-27 23:47

So

char** argv or char* argv[]

Name: Anonymous 2011-10-28 0:08

>>46
The only acceptable ones are:
char ** argv
char **argv
char *argv[]

Only retards paste the pointer to the first type, do you even know what happens if you write char* a, b?

Name: Anonymous 2011-10-28 0:10

>>47

The same could be said about char *a, b

Name: Anonymous 2011-10-28 0:13

>>48
You could say it. You'd be wrong.

Name: Anonymous 2011-10-28 0:14

>>43

Haha, what an idiot!


int foo()
{
    // Create two 1000x1000 unit matrices:
    Matrix a, b, c;
    if(!Matrix_init(&a, 1000, 1000)) goto exit_foo;
    if(!Matrix_init(&b, 1000, 1000)) goto exit_foo;

    // Do something with a and b here, for example:
    if(!Matrix_init_with_matrix(&c, &a)) goto exit_foo;
    if(!Matrix_multiply_by_constant(&c, 2)) goto exit_foo;
    if(!Matrix_add(&c, &b)) goto exit_foo;
    ...

 exit_foo:
    Matrix_destroy(&a);
    Matrix_destroy(&b);
    Matrix_destroy(&c);

    return some_value;
}


He should have written that as:



int foo()
{
    // Create two 1000x1000 unit matrices:
    Matrix a, b, c;
    if(Matrix_init(&a, 1000, 1000))
    {
        if(Matrix_init(&b, 1000, 1000))
        {
            // Do something with a and b here, for example:
            if(Matrix_init_with_matrix(&c, &a))
            {
                if(Matrix_multiply_by_constant(&c, 2))
                {
                    if(Matrix_add(&c, &b))
                    {
                    ...
                    }
                }
            }
        }
    }

    Matrix_destroy(&a);
    Matrix_destroy(&b);
    Matrix_destroy(&c);

    return some_value;
}

Name: Anonymous 2011-10-28 2:58

GC is shit.

Name: Anonymous 2011-10-28 4:10

Tried to write a windows application in C. The language is really not suited for it. I barely got anywhere before I gave up. Ugly fucking code. Ugly. It was so ugly.

Name: Anonymous 2011-10-28 4:16

>>52
Hah, if you think that's ugly, try Lisp!

Name: Anonymous 2011-10-28 5:39

>>50
This pisses me off, clearly the expert solution is:


int
foo (void)
{
  Matrix a = {0},
         b = {0},
         c = {0};
   
  matrix_init (&a, 1000, 1000);
  matrix_init (&b, 1000, 1000);
  matrix_init (&c, 1000, 1000);

  matrix_value_from (&c, &a);
  matrix_multiply_scalar (&c, 2);
  matrix_add (&c, &b);
   
  if (a.error_flag ||
      b.error_flag ||
      c.error_flag)
      goto exit_foo;

  ...

  exit_foo:
    matrix_free (&a);
    matrix_free (&b);
    matrix_free (&c);

    return some_value;
}

Name: Anonymous 2011-10-28 6:05

>>54
goto is evil and you should be ashamed of yourself

Name: Anonymous 2011-10-28 6:11

>>55
Forward goto for error handling is considered beneful.

Name: Anonymous 2011-10-28 7:06

>>56
YOU LIE GOTOs ARE BAD BAD BAD, THAT IS MY INSTRUCTOR TAUGHT ME

Name: Anonymous 2011-10-28 7:10

>>57
It's an oversimplification, just as saying ``global variables are evil''.

Name: Anonymous 2011-10-28 7:59

GC approved GOTO

(define (foo)
  (let ((some-value 0)
        (a (matrix))
        (b (matrix))
        (c (matrix)))
    (call-with-current-continuation
     (lambda (goto-exit-foo)
       (unless (matrix-init! a 1000 1000) (goto-exit-foo))
       (unless (matrix-init! b 1000 1000) (goto-exit-foo))
       (unless (matrix-init-with-matrix! c a) (goto-exit-foo))
       (unless (matrix-multiply-by-constant! c 2) (goto-exit-foo))
       (unless (matrix-add! c b) (goto-exit-foo))
      
       ...
      
       )
     )
;exit-foo:
    (matrix-free! a)
    (matrix-free! b)
    (matrix-free! c)
    some-value
    )
  )

Name: Anonymous 2011-10-28 8:11

>>59
call/cc is way more powerful than goto (it's also typically less efficient, but this depends on how it's implemented, it's possible theoretically to implement it more efficiently, but that may come at the cost of total program speed(implementation-dependent)).
Common Lisp's go special form and C's goto will typically just get compiled as an unconditional jump (possibly with whatever stack adjustment is required, if the implementation makes use of a stack).

Name: Anonymous 2011-10-28 9:34

>>60
comparing call/cc and goto

FUCK

OFF

Name: Anonymous 2011-10-28 9:49

>>58
Global variables pollute namespace. Goto breaks structured programming design.

Name: Anonymous 2011-10-28 9:53

>>62
Pointless OOP and exceptions are much more harmful than global variables and goto.

Name: Anonymous 2011-10-28 10:09

>>61
Lambda is the ultimate goto.

Name: Anonymous 2011-10-28 10:12

Lambda: The Ultimate Spaghettive

Name: Anonymous 2011-10-28 13:49

call/cc is the identity function with the return point and its argument reversed.

Name: Anonymous 2011-10-28 15:28

How can I make this better?

#include <stdio.h>
void main(int i){
  char *a[]={"fizz\n","%d\n","%d\n"},*b[]={"fizz","",""};
  for(;i<101;i++)
    (i%5!=0)?printf(a[i%3],i):printf("%sbuzz\n",b[i%3]);}

Name: Anonymous 2011-10-28 17:03

>>67
#include<stdio.h>
main(int i){char**a={"fizz\n","%d\n","%d\n"},**b={"fizz","",""};
while(++i<101)(i%5)?printf(a[i%3],i):printf("%sbuzz\n",b[i%3]);}

Name: Anonymous 2011-10-28 19:41

>>68
That gives warnings

Name: Anonymous 2011-10-28 20:04

main(i){for(;i<101;puts(i++%5?"":"buzz"))printf(i%3?i%5?"%d":"":"fizz",i);}

Name: Anonymous 2011-10-28 21:01

>>70
C newbie can't do fizzbuzz with less than four conditionals.

Name: sage 2011-10-28 21:06

ever tried nesting the ternary operator ? I tried and it reminded me of Lisp and all the fancy functional languages that are frequently discussed in places such as this one by you expert programmer people really i'm just a teenager

Name: Anonymous 2011-10-28 21:07

>>72
whoops put the sage in the wrong box anyway enjoy your sage

Name: Anonymous 2011-10-28 21:49

>>73
counter sage!

Name: Anonymous 2011-11-03 16:08

Someone needs to make a C submission here to unseat JavaScript:
http://shootout.alioth.debian.org/u64/performance.php?test=regexdna

Name: Anonymous 2011-11-03 16:32

>>75
sort by Memory
woot C/C++ beast

Name: Anonymous 2011-11-03 16:51

>>75
No, it would only prompt FVimpostor to make threads about him optimizing the JS solution by storing the natural numbers in named variables.

Name: Anonymous 2011-11-03 17:02

storing the natural numbers in named variables
Awesome idea! But, should that be extern variables or constants?

Name: Anonymous 2011-11-03 17:05

>>77
Too bad optimizations of source code are not usually accepted submissions.

Name: Anonymous 2011-11-03 17:57

>>79
And?

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