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

Pages: 1-4041-8081-

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-24 21:51

C gets too much credit for being the `first' standard, portable programming language. FORTRAN 66? ALGOL 68? Hell, even the early Lisps were quite well standardized.

Where did this myth that C was the `first' come from, exactly?

Name: Anonymous 2011-10-24 21:51

no it's not

Name: Anonymous 2011-10-24 22:00

>>2
That's not why C gets credit. It gets credit because it's an incredibly versatile, simple, and has great syntax.

Name: Anonymous 2011-10-24 22:18

>2011
>still talking about C

mfw this is a text-only board.

Name: Anonymous 2011-10-24 22:23

C will be phased out once we figure out that squeezing the last drops of performance out of a single core is not a good idea and programmers in general stop being so resistant to learning new things.

Name: Anonymous 2011-10-24 23:15

>>5
polecat kebabs

Name: Anonymous 2011-10-24 23:24

>>6
Phased out for what? Java, C++, and C#?

Name: Anonymous 2011-10-25 0:02

>>8
no, something without imperative AIDS.

Name: Anonymous 2011-10-25 0:07

Name: Anonymous 2011-10-25 0:33

>>10
Eh, just looks like another HTML-to-PDF conversion. Might as well just find the original HTML file:
http://dhorizon.3x.ro/upload/Kernighan&Ritchie/kandr.html

My personal favourite copy is:
http://library.nu/docs/R2EUSNA6HW/

Does nobody have the original troff sources floating around? It would be trivial to make a `proper' PDF copy complete with the original diagrams, and I would gladly pay for a DRM-free ebook. They could dedicate it to Dennis Ritchie or something.

Name: Anonymous 2011-10-25 4:00

C hasn't been updated min decades, unlike C++0X

Name: Anonymous 2011-10-25 4:01

>>12
C hasn't been updated max decades

Name: Anonymous 2011-10-25 4:50

>>12
B-but there's C1X...

Name: Anonymous 2011-10-25 6:01

>>14
There's no C1X.

Name: Anonymous 2011-10-25 6:02

>>14
There's no C1X.

Name: Anonymous 2011-10-25 6:33

>>15,16
Habeeb it.

Name: Anonymous 2011-10-25 7:32

>>8
Go.

Name: Anonymous 2011-10-25 8:08

>>6
But C supports threads!

Name: Anonymous 2011-10-25 11:18

>>19
C supports everything+everything inline asm does

Name: Anonymous 2011-10-25 11:31

i just started learning C after a year of haskell and lisp.


this level of abstraction makes me want to die. everything is done with conditionals and loops wtfff

Name: Anonymous 2011-10-25 11:34

>>21
Make a `for_each' macro and understand pointers and structures. When you master C and don't fear to abuse the preprocessor, things can be pretty well abstracted.

Name: Anonymous 2011-10-25 11:45

>>21
Try writing inline functions and macros, use _msize and malloc_size for pointers.

Name: Anonymous 2011-10-25 12:19

When you write a line of C you have a good idea of how much actual work it's going to make the computer do.

e.g. with for (i=0;i<10;i++) a[i]=i*i; you have a multiply, a store, and a comparison.

The same thing in a more abstracted language might involve looking stuff up in a symbol dictionary, mallocs, creating objects on the heap, reference counting, garbage collection, blahblahblah, hundreds and hundreds of cycles.

That's why I like C, you know what's going on underneath.

Name: Anonymous 2011-10-25 12:59

>>24
And then, you're optimizer fucks uSegmentation fault

Name: Anonymous 2011-10-25 14:43

I suspect that this thread was created in order to draw the C-tards out of this thread: http://dis.4chan.org/read/prog/1319206002 and I think that it was about 60% effective

Name: Anonymous 2011-10-25 20:39

>>11
There was a partial TeX version posted on /prog/ a year or two ago.

Name: Anonymous 2011-10-25 21:57

>>26
>>language fight
>>i'm a real programmer

Name: Anonymous 2011-10-25 22:00

>>23
Try writing inline functions and macros, use _msize and malloc_size for pointers

That is really wrong. WTF? Are you trolling? Or are you just plain stupid.

Name: Anonymous 2011-10-25 22:02

>>19
But C supports threads!

Can you cite the exact passage in anyone of the the various C standards that mentions threads? Because for the life of me, I don't see any mention of them in any of the standards.

Name: Anonymous 2011-10-25 22:10

>>30
GO SCRUB MIDGET

Name: Anonymous 2011-10-25 22:42

>>31
You still haven't cited the passage that mention threads in one the various C standards. Could it be because threads aren't portable?! No way. Uh huh. Now tell us all what you do for a living again bitch.

Name: Anonymous 2011-10-25 22:49

I have a very serious question C. I see people dynamically allocate memory when the memory isn't variable at all. Why would they do this?

Name: Anonymous 2011-10-25 22:55

>>33
You ain't gonna get a quality C answer here. This is because 98% of the idiots only know know the loser language called lisp. Of those 98%, 80% working hourly general labor jobs not related to computer programming, and the other 18% just does shit jobs like maintaining software or writing simple test scripts.

Name: Anonymous 2011-10-25 23:07

>>34
4/10. The see me toolin, they hatin.

Name: Anonymous 2011-10-25 23:25

>>33

because they dumb

Name: Anonymous 2011-10-26 0:03

>>33
Probably because they want the object to outlive the scope of the function they're in.

Name: Anonymous 2011-10-26 15:51

>>37
That doesn't make any sense. That's not the best way to do it.

Name: FrozenVoid 2011-10-26 15:58

>>38
Best way: create a system of global static buffers with (lock/full) flags and write to them.
Easy way:malloc

Name: Anonymous 2011-10-26 16:02

>>39
fuck off and die you too

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?

Name: Canada Goose uk 2011-11-03 23:34

Just to say,I am glad to read so good article in the webstie.<a href="http://www.canadagoosemart.org">Canada Goose parka</a> Well,OK.I have to say,what a wonderful blog it is.thank you for your sharing so good articles in the website.I like it very much.It is very interesting in it<a href="http://www.canadagoosemart.org/canada-goose-yorkville-parka">Canada Goose Yorkville Parka</a> .Look forward to reading so good articles in the website.

Name: FrozenVoid !!mJCwdV5J0Xy2A21 2011-11-04 4:44

>>78
If you have a hundred mentions of single number its easier to set it to constant.
Since JsvsScript lacks #define const are the closest thing to control large amount of same numbers at once.
Note;blindly replacing every number with a named constant is useless. Its meant for chunks of code that use that number for one purpose.
Its like:
you have code which adds 3.5 to 8 variables. Instead of writing 3.5 every time you change the line you can make it a const ADD_NUMBER_35
when time is to change ADD_NUMBER_35 to 10 you just change one line.

Name: Anonymous 2011-11-04 7:53

>>39
there's a way to do this without polluting the global scope (which is better than your 'best' way).
define a struct which has a pointer to the data and a write lock handle.

Name: Anonymous 2011-11-04 8:11

you have code which adds 3.5 to 8 variables. Instead of writing 3.5 every time you change the line you can make it a const ADD_NUMBER_35
when time is to change ADD_NUMBER_35 to 10 you just change one line.
I laughed out loud, slapping meself on my meaty thighs!

Name: FrozenVoid !!mJCwdV5J0Xy2A21 2011-11-04 8:16

>>83
I don't trusts struct and such OOP terms as "polluting the global scope"(especially when your goal is to provide global access to a region of memory)
you're polluting your mental scope with structs and reifications of things.
In fact, have you ever wondered how you allocate a struct or select one?
Do you ignore the complexities you create in your mindless quest for "pureness of form"?

Name: Anonymous 2011-11-04 9:16

the practice of NAMING_CONSTS_LIKE_THIS is fucking retarded

Name: FrozenVoid !!mJCwdV5J0Xy2A21 2011-11-04 9:42

>>86
You don't have to use them. If its effective for its purpose and looks ugly, its still useful for some things.
Changing constant numbers in 70 places by hand is far more "fucking retarded" than my single #define

Name: FrozenVoid !!mJCwdV5J0Xy2A21 2011-11-04 9:48

The names looks "CAPS LOCK ugly" to catch attention, so you will never accidentally confuse it with a normal variable like
addnumber35(which is modified by program) vs ADD_NUMBER_35  (which is set and changed by you only).

Name: Anonymous 2011-11-04 9:54

>>88
Why would you ever define ADD_NUMBER_35 to be 10?

Name: FrozenVoid !!mJCwdV5J0Xy2A21 2011-11-04 9:59

>>89
Because I hack programs. There two ways to quickly change programs, use some text replace on block of text or just change a couple of controlling constants(you don't usually touch anything named with capslock(its like a Hazard sign to avoid accidental changes)).
In large programs changing #defines is far faster than using text replace or manually rewriting the parts of code with these constants.

Name: Anonymous 2011-11-04 10:02

>>88

i'd rather have my code less ugly than have it immediately apparent which things are constants. i realize i'm in the minority as most people use YELLING_AT_YOU const naming style

Name: Anonymous 2011-11-04 10:10

>>90
I am not questioning the usefulness of constants. That damn constant has ``35'' in its name, why would you ever change it to 10‽

Name: Anonymous 2011-11-04 10:14

>>79
Huh?

Name: FrozenVoid !!mJCwdV5J0Xy2A21 2011-11-04 10:21

>>92
35 is placeholder for what value supposed to be intially. It could change at the course of the program, but most likely you'll change it back to default value (that being 35). I see no problem  with #define ten 10000 as long as its useful to change ten.
example you have a huge array operation inlined and referenced in several places with
x[i]
x[i+1]
x[i+2]...
But suddenly you want to change format of underlying array for performance testing
instead of hunting down where +1 or +2 reside and manually setting them to +4 +8 , you just change
ADD2 to 8 and ADD1 to 4, and entire program works as expected.
If you don't like it you just change the constants back to 1 and 2.

Name: Anonymous 2011-11-04 10:28

>intially
C rots the brain

Name: Anonymous 2011-11-04 10:42

>>94
You should use some symbolic name then, such as ADD_NUMBER_A or ADD_FIRST_NUMBER, then have a comment next to the definition describe what the value should do. Putting the literal in the name of a value that's going to be changed in the future is utterly retarded.

Name: Anonymous 2011-11-04 10:43

>>93
The code has to follow the algorithm they give.

Although that particular benchmark is not really about programming languages but "which programming language has the fastest PCRE binding", given what the submissions are. A good implementation of the Thompson algorithm would probably beat the JS one (which is also not PCRE but Google's own.)

I saw this posted on /prog/ too:
http://swtch.com/~rsc/regexp/regexp1.html

Name: FrozenVoid !!mJCwdV5J0Xy2A21 2011-11-04 10:52

>>96
 if you want to modify it, you'll have to adapt to some quirks of naming conventions.
I don't want to change some number 99% of the time, and i want to have reminder in case i change it.
ADD_NUMBER_35 //contains default number embedded in itself
ADD_NUMBER_ARRAY_OP_HFIX_NEW// contains zero information beside its location.
If you have one ADD_NUMBER_ARRAY_OP_HFIX_NEW its fine to remember what values it should have,but what if you have 3-4 such similar named constants like  ADD_NUMBER_ARRAY_OP_MFIX_NEW? What makes them different? Thats just useless semantic noise.

Name: Anonymous 2011-11-04 11:10

>>98
If you don't think you'll be changing it, then leave it as a literal. Otherwise, give it a meaningful name that does not include its literal value.

Name: FrozenVoid !!mJCwdV5J0Xy2A21 2011-11-04 11:17

>meaningful name that does not include its literal value.
I'm not going to waste time at inventing a name for every single const or variable.
Names should be self-descriptive about their content.

Name: Anonymous 2011-11-04 11:19

>>100
Then it'll only confuse you later on when you try to maintain old code. Even if you're somehow able to deal with that, anyone else looking through your code likely won't.

Name: FrozenVoid !!mJCwdV5J0Xy2A21 2011-11-04 11:22

>>101
I'm not maintaining anything.I'm not a software developer.

Name: Anonymous 2011-11-04 11:23

Source code readability is unscientific and ultimately destructive.

Name: Anonymous 2011-11-04 11:35

>>102
Not a reason not to write good-looking code.
But whatever. Do as you want.

Name: Anonymous 2011-11-04 11:35

>>101
Please stop responding to the invisible poster. It unsettles me greatly.

Name: Anonymous 2011-11-04 11:38

>>105
Good to know, I'll make an effort to answer him more often.

Name: Anonymous 2011-11-04 11:46

>>105
I could include the whole content of his posts in mine, if you're unable to view them.

Name: Anonymous 2011-11-04 11:48

>>107
That's a nice idea too.

Name: Anonymous 2012-11-09 15:27

>>11
First link still works but second is dead. Thought I'd let you all know.

Name: Anonymous 2012-11-09 15:50

>>33
static memory allocation is contiguous. Dynamic memory allocation isn't. So you can create linked lists and such using dynamically allocated memory.

Name: Anonymous 2012-11-09 15:51

>>11
linking to library.nu
That is wrong man. FUCK YOU

Name: Anonymous 2012-11-09 16:07

>>111
;_;

Name: Anonymous 2012-11-09 16:10

Name: Anonymous 2012-11-09 17:59

>>113
I know about this and the other mirrors. It's not the same as library.nu.

Name: Anonymous 2012-11-09 18:13

>>114
what kind of hipster books are you trying to download?

Name: Anonymous 2012-11-09 19:47

>>32
`` http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1516.pdf ! ''

``7.25 Threads <threads.h> . . . . . . . . . . . . . . . . . . . 372''

Name: Anonymous 2012-11-09 20:13

C is ancient worse-is-better shite, much like this thread.

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