C programming

Where do I start?

Other urls found in this thread:

en.wikibooks.org/wiki/C_Programming
sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/x86_64/strcpy.S;h=3f90c0020a25f2899e5cf74b6077df2f4cbfaada;hb=HEAD
insecure.org/stf/smashstack.html
c.learncodethehardway.org/book/
hentenaar.com/dont-learn-c-the-wrong-way
c-faq.com/decl/spiral.anderson.html
youtube.com/watch?v=S5S9LIT-hdc
tutorialspoint.com/compile_c_online.php
cl.cam.ac.uk/~pes20/cerberus/notes50-survey-discussion.html
open-std.org/JTC1/SC22/WG14/www/docs/n2012.htm
twitter.com/AnonBabble

Terry Davis, HolyC will teach you pretty quickly

string operator = /* Find this answer out */
printf("%s is the basis for all structural data", data, operator);

>C

don't bother, there are literally no C jobs last time I checked

Dont care about a job

int main() { ....

en.wikibooks.org/wiki/C_Programming

There are no strings in C fucking noob. Ignore autistic people that can't socialize properly so don't get jobs. I'm literally debugging a Linux kernel by fucking with the C code and getting paid $$ by a mid size company.

OP, there is only 1 book you need:

The C Programming language second edition, ANSI C. By Denise Ritchie and Brian Kernighan

Only textbook I actually care about. It's short, to the point, fucking amazing. Just buy it or find one of the gazillion ebooks out there. It's from the like fucking 80s

It's the language with the highest success/atrociousness ratio.
C programming a modern approach is good because it explains a lot of the pitfalls of C, and C has many.

open a .pdf reader (for the K&R book) and two terminal windows (one for text editing, another for compiling).

>The C Programming language second edition, ANSI C. By Denise Ritchie and Brian Kernighan

No, stop the meme

>while(*d++ = *s++);

No, just no.

HAH! i wrote that shitty code on purpose! Now who's the shitty n00b :)))))))))))))))))

Sams Teach Yourself C in 24 Hours

What IDE/Text editor to use if I want to write C in linux? no vim/emacs please I can't handle that right now

anything with autocomplete?

Yeah it's not perfect, but you're going to encounter legacy code that does that. Every neet thinks it's all about writing perfect maintainable code, but the real world is dealing with other people and older standards.

Besides, that book gives me the tools needed to understand your line of code (or, in this case, it's compiler/architecture independent.)

Gedit is comfy. Or else np++ through wine.

I only use visual Studio when doing .NET development for autocomplete because .net languages were designed for autocomplete. C wasn't really, you don't need it. As horrible as it is, grepping through the linux kernel looking for the correct variable name/function is a lot more valuable than the tracing of the stack

Notepad++

doesn't have an error detector as far as i've seen, however.

>Besides, that book gives me the tools needed to understand your line of code (or, in this case, it's compiler/architecture independent.)

But it does not give you the tools to avoid all the pitfalls. It's always been memed as the definitive bible on C, but that book is the single greatest culprit for buffer overflows, ever.

how do you all feel about C in Netbeans or Eclipse?

i don't use them but you can try sublimetext or atom
notepad++ does work on wine btw

this. there are much better books out there, like "Pointers on C"

C Primer Plus is solid

Not OP.

I just bought Programming in C (4th Edition) by Stephen G. Kochan. Literally a few minutes ago.

How did I do?

Not OP, but how is K N King's C Programming: A Modern Approach?

Pretty good, it's the way to go together with "Pointers on C".

I really liked that book. Do all the examples and all the exercises (like, write them out, compile them, get them to run). You'll learn a lot.

Are you totally new to programming? If so check out C Programming Absolute Beginners Guide 3rd Edition by Greg Perry. Solid intro book even if it does look a little childish.

Very good book. Probably one of the best if you already have a little experience in another language such as visual basic. Doesn't have to be much experience, just a basic understanding that you write code then compile it to get an executable, understanding your computer has temporary (volatile) memory (RAM) and long term (non-volatile) memory (HDD/SSD), you can store things in RAM super quick compared to a HDD, etc.

It is a great book. Kochan write good.

You shouldn't begin with it but you should eventually read Expert C Programming Deep C Secrets

>while(*d++ = *s++);

They actually have that in the book? Wow, just wow.

Can you explain why that is bad?

That code triggers me so much
I bet K & R though they were clever when they thought of it.
Still better than the glibc strcpy
sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/x86_64/strcpy.S;h=3f90c0020a25f2899e5cf74b6077df2f4cbfaada;hb=HEAD

Buffer overflows, people being incredibly stupid, causing 99% of code execution vulns
insecure.org/stf/smashstack.html

Difficult to read. It's easy when it's done in a small program, but when you have tens of thousands of lines of code written like this, it's going to be hard to maintain the code. But, in the context of his time, they probably had to do this because of memory and data storage limitations.

>Don't bother learning to play the violin. The jobs are taken.
>Don't bother with gardening your own roses. It's a terrible investment.
>No point in learning Russian. It takes way too long to reach the level of a two-way interpreter.
>Don't bother swimming. The competition for the Olympic team is hard and you're too old to start anyway.

Two reasons:
- one is stylistic, because of terseness and because the operator precedence are not obvious, but this is a minor objection
- the second one is a semantic one: this function does copy only well formed null terminating strings, it can create all sorts of havoc if used incorrectly, and is a prime example of why C is such an insecure language

all of those things are true tho

>I bet K & R though they were clever when they thought of it.

They still do, probably.

>Null terminated strings

Literally a (multi) billion dollar mistake.

if you're not terminating your strings correctly, you shouldn't be using strcpy anyway
That's what strncpy is for.

K & R... Historical reasons. Plus it'll impress other programmers you have it even though you'll never use it or read it.

C in a Nutshell - Prinz and Crawford. For doing your shit with. Covers C11 and C99.

Null terminating string are just a bad idea.
Are there any other languages beside C that use them?

Though these are all true, C knowledge is still highly sought after in fields where speed matters.
Hell, some people in my company program in Assembly.

C99 and C11 are such minimal additions to C, they don't require their own books.

>C99
oh wow some gnu extensions got standardized, you can use strncpy portably now
>C11
oh wow there's a mulithreading library, and it's optional
oh there's a bool type now, cool i guess

>oh there's a bool type now, cool i guess

Let me guess, it's implemented like this:

typedef char bool;
#define TRUE 1
#define FALSE 0

Truth is not the highest level of understanding m8.

...

This website is the bomb for c.
c.learncodethehardway.org/book/

so..

there's no string

is there a way to print out a char array, besides using a loop?
char arr[]="Some message here"

yes, printf

Nigga, look up pointers and that's all you'll ever need to know about C. Almost everything is an abstraction built on top of pointers.

That books is absolute shit
hentenaar.com/dont-learn-c-the-wrong-way

zed shaw is such a faggot

>Not learning programming languages the hard way

Why even get up in the morning

It is funny because neither Learn C the Hard Way nor K&R are good ways to learn C.
A much better resource is either "C Primer Plus" or "C Programming A Modern Approach".

true. some other good books are
>Programming in C by Kochan
>C Programming Absolute Beginner's Guide by Perry
>Beginning C by Horton
>Head First C by Griffiths

No, just no

The main critisim seems the be the auther attitude( wich seem irrelevent to me) and the fact that the auther does not give the reader everthing he needs to know ( instead insisting that the reader do his own research). I liked it because it teaches you how to find answers and to think critically. Mind you I started the tutorial as a complete novice and I'm not saying I'm still not one, but Never did I feel lost or out of options. also keep in mind the title " learn c the hard way"

Sublime is baller.

Oh, I assumed if the code was hard for me to understand, it means I need to gain more fluency in C. In other words, I need to bring myself up to their level, not force them to simplify their code down to babby mode that children can understand.

I thought that if I didn't understand every little order of operations trick and idiosyncrasy out there in industry, people would smugly say "Lol learn2C newfag". I spend an unhealthy amount of time studying complex declarations like pic related. This thread makes me think I'm not as retarded as I thought.

My biggest difficulty in reading kernel code right now is the amount of constants and macro definitions fucking everywhere. I remember watching a video where Linus Torvalds said he can read C code just as if he's reading English and immediately know what the code is doing. I'd like to be at that level someday.

That image isn't even correct. They're pointers to functions that return pointers to functions that return void.

c-faq.com/decl/spiral.anderson.html

How do you know he's not lying?

Linus? I guess we don't.

I found the video.

>I don't know, maybe I'm autistic or something.

youtube.com/watch?v=S5S9LIT-hdc

>This thread makes me think I'm not as retarded as I thought.

C has something like 18 level of operator precedence. Now, for the expert programmers this is a plus, but it is the root of unreadable declaration like that.
There are languages without operator precedence where you (if they had the right semantics) could do such a thing without effort.
C is cleverly retarded.

void (*(*f[])())()
declare f as array of pointer to function returning pointer to function returning void

i = 1;
i = ++i++;
printf("%d\n",i);

So, you have to basically parse the expression from inside out?

Start with the Greeks.

>error: lvalue required as increment operand

Wow, amazing how you've figured this out. Most C programmers don't figure this out in years.

doesn't compile

Figure out the basics from any C book/website, start working on Project Euler and google new stuff as you go.

Learning Scheme helps.

he was trying to explain what it's like to program to non-programmers in that video. it was a throw-away line that you've read too much into. he wasn't saying he could take any inscrutable mess of code and instantly understand it.

tutorialspoint.com/compile_c_online.php

#include

int main()
{
int i = 1;
printf("%d\n",++i + i++);

return 0;
}

Prints 5.

I thought first the postfix increment would increment i from 1 to 2, then return the value before it was incremented, which is 1.

Then the prefix increment would increment 2 to 3, so you'd have 3 + 1 = 4.

Why does the postfix rule only apply to stuff like return(i++) or array[i++]? The postfix rules are the biggest bullshit to understand about C.

It's time to read the C standard.

#include

int main()
{
int i = 1;
printf("%d\n",i++ + ++i);

return 0;
}

If you switch the order it prints 4. I'm tripping balls over here.

It's undefined behavior, the compiler can do whatever the fuck it wants in that situation and it's correct.

>The expression ++i++ is evaluated as ++(i++) which is illegal in C as the postfix increment returns a value and prefix incrementing on a that value makes no sense.

>What you have is somewhat equivalent to: ++(5) which is obviously illegal as you can apply prefix increment on something that's not a l-value.

is correct, if the compiler caused the code to rm -rf --no-preserve-root / it would still be correct
But what's happening is the i++ is increasing it to 2 and then then ++I is increasing i to 3 and then adding them

>If you switch the order it prints 4. I'm tripping balls over here.

Welcome to C. I don't think this kind of code shows up in real life, it's there just to show the poor lit corners of the language. Can experienced C programmer confirm?

...

Unfortunately, you're wrong
cl.cam.ac.uk/~pes20/cerberus/notes50-survey-discussion.html

>Can experienced C programmer confirm?

According to the language spec, the result is undefined. There is no definition whether the arguments of an arithmetic operator (+ - * /) are evaluated from left to right, or right to left -- the implementation is free to do it either way. The only operators with a specifically defined order are && and ||, which are always evaluated left to right.

Amazing stuff.

Where did you find this?

open-std.org/JTC1/SC22/WG14/www/docs/n2012.htm

Start with A and then do B before getting to C.

>There are no strings in C fucking noob
the standard says you're retarded

looks pretty standard and straightforward

>Difficult to read
only if you don't know C

Undefined behaviour. Any result is meaningless.

>because the operator precedence are not obvious
it's obvious if you know the language; only """web developers""" expect to read and write code without knowing the language
>only well formed null terminating strings
that's the only kind of string

you guessed wrong

there's also the fact that the author doesn't know C, by his own admission; he just hunted for random information to write the book

>that's the only kind of string
For writing serious exploits

for everything

no.

yes

You are going senile, Brian.

Realize that everything you do in C essentially revolves around manipulating buffers of memory. Things like "strings" make more sense when you look at everything as just chunks of memory. Pointers and arrays become a lot easier to reason about when you're thinking in terms of locations of memory and ranges of bytes from a location.