Let's have a thread for the C programming language. It's an excellent language.
Name:
Anonymous2011-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:
Anonymous2011-10-24 21:51
no it's not
Name:
Anonymous2011-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:
Anonymous2011-10-24 22:18
>2011
>still talking about C
mfw this is a text-only board.
Name:
Anonymous2011-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.
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.
>>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:
Anonymous2011-10-25 11:45
>>21
Try writing inline functions and macros, use _msize and malloc_size for pointers.
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.
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:
Anonymous2011-10-25 20:39
>>11
There was a partial TeX version posted on /prog/ a year or two ago.
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.
>>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:
Anonymous2011-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:
Anonymous2011-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.
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;
...
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))
{
...
}
}
}
}
}
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.
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:
Anonymous2011-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).
call/cc is the identity function with the return point and its argument reversed.
Name:
Anonymous2011-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]);}
>>70
C newbie can't do fizzbuzz with less than four conditionals.
Name:
sage2011-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
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!!mJCwdV5J0Xy2A212011-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:
Anonymous2011-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:
Anonymous2011-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!!mJCwdV5J0Xy2A212011-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"?
the practice of NAMING_CONSTS_LIKE_THIS is fucking retarded
Name:
FrozenVoid!!mJCwdV5J0Xy2A212011-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!!mJCwdV5J0Xy2A212011-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:
Anonymous2011-11-04 9:54
>>88
Why would you ever define ADD_NUMBER_35 to be 10?
Name:
FrozenVoid!!mJCwdV5J0Xy2A212011-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.
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:
Anonymous2011-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‽
>>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:
Anonymous2011-11-04 10:28
>intially
C rots the brain
Name:
Anonymous2011-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.
>>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.)
>>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:
Anonymous2011-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!!mJCwdV5J0Xy2A212011-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:
Anonymous2011-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!!mJCwdV5J0Xy2A212011-11-04 11:22
>>101
I'm not maintaining anything.I'm not a software developer.
>>11
First link still works but second is dead. Thought I'd let you all know.
Name:
Anonymous2012-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:
Anonymous2012-11-09 15:51
>>11 linking to library.nu
That is wrong man. FUCK YOU