The C Programming Language

The C Programming Language.

Attached: 0131103628.jpg (438x576, 322K)

Other urls found in this thread:

zedshaw.com/2015/01/04/admitting-defeat-on-kr-in-lcthw/
twitter.com/SFWRedditGifs

epic

Does it have any modern-day usage that can't be replicated by C++?
Only thing I imagine is binary sizes for muhhhh embedded.

Fuck C, at DasBetterC or Rust is where it's at these days.

C++ is a pajeet-tier clusterfuck.

Have you read The C Programming Language front to back?

The C programming language.

The Pleasure of Being Cummed Inside

based and redpilled

The C Programming Language

The C Programming Language.

user YOU FUCKED UP WITH THE FILENAME
3/10 MADE ME USE CAPS LOCK

>go to job interview
>Interviewer: "so, what programming languages are you most proficient in?"
>me: "mostly proficient in C, but I've dabbled around with a few assemblies here and there."
>Interviewer: "ah the classics, that's great. but how are you with JavaScript and/or Python? "
>me: "what did you just say?"
>Interviewer: "JavaScript or Python?"
>me: "im sorry, i don't recall being a retard as a qualification for this job. thanks for your time."
>turn 360 degrees and walk out the door

Attached: 1535222436614.jpg (600x878, 109K)

C is used when people want to be absolutely sure what kind of binary the code generates without having to actually read assembly. Embedded stuff is usually compiled with -O0. C++ is more about letting the compiler do whatever and not giving a fuck

ITT:

The C Programming Language

your thoughts?

is this still the best resource to learn C as a ROOOKIE?

>Not a retard
>literally spun around in place before leaving like a fucking autist
>and then everyone clapped

> Opens "The C Programming Language" by Brian W. Kernighan and M. Ritchie to page 1
> Begins reading

may as well just throw "newfag" in the name field at this point, user.

One of many programming and CS books I keep on my bookshelf to look like the king of Jow Forums

but have never read or studied

kill me

> pic related, it's not me.jpg

Attached: stock-photo-man-reading-in-library-flat-illustration-hipster-modern-style-geek-with-beard-and-glasse (450x470, 38K)

zedshaw.com/2015/01/04/admitting-defeat-on-kr-in-lcthw/

The C Programming Language

>t. believes c++ is like java

There is zero reason to start a new project in C nowadays.
Learning C is useful for maintaining and working on projects already written in it, though.

its alright.
definitely not for the absolute beginner of programing

You have no idea what you're talking about.

I know exactly what I'm talking about

I use C because I cant comprehend other languages.
They are either too descriptive,abstract or whatever the current trend is.

That is NOT why people use C. If you are using C for that reason, stop immediately. C is not for you.

The reason they use it is unironically

The only retard here is you. Good job.

>The C Programming Language.
The C Programming Language.

360 is a full spin, you would be facing the interviewer again you dumbass

This. C++ always makes me feel like I'm not writing the most elegant/zero-overhead abstraction whereas with C you can write some disgusting macro-infested encapsulation breaking code and its pretty much on par with most C code out there.

I don't know man. no lambdas, no member functions, void pointers in place of generics, can't really get into c. maybe if I do some embedded work I'd come around to it.

Nope

It was a great book for it's time, but it's more of a meme than a great book to learn from in the current year. Definitely spend a few hours glancing through it sometime and admire it's the beautiful documentation and historical significance though.

>no member functions
What do you mean?

The C Programming Language

C programming by Kochan is a much better book objectively speaking.

K&R is good as a "let me brush up on my C" kind of book.

You can't declare functions inside structs in C, right?

I use assembly

Thats a lie i use python

Fucking based, all the pajeets i know use gay shit like c++ and go

C supports complex data structures with structs, but no way to internally operate on that data. You can use functions pointers, but I don't see the point, you'd still have to declare the function outside of the struct, defeating the purpose.

Nope

You're just too stupid to wrap your head around OOP.

You can declare pointers to functions. How is that an inconvenience?

So what if you have to _define_ it outside of the struct? People have used function prototypes for decades, and still do.

Well one is a function, the other is a pointer to function. They're semantically different.

this

Yeah but it's not namespaced properly.

Yes, and they're free to do so. Like I said before, that's just not for me.

I still don't see the inconvenience.
Uh huh.
Fair enough.

Come on now, declaring function pointers was not the issue; anyone can see the utility of function pointers. The issue is the inability to make functions inside of structs.

>inconvenience
Nevermind the asterix, you're solving the same problem in a wrong way. It's a workaround for something C++ supports natively.

You'd be declaring the function twice for no reason and you'd have to pass the address of the object anyway, so you'd be making extra work for yourself and wouldn't get the syntactic benefit of methods anyway.

I'm using C because I don't like all the extra C++ syntax and boilerplate

C and Python so comfy

Attached: nom.png (900x1273, 618K)

You prefer writing 50 lines of code to calling a readily available piece of code.

So what? Why do you need to define the function in the struct?
Again, prototypes exist.

You all sound like you are making excuses for the baby bird syndrome.

>So what? Why do you need to define the function in the struct?
Namespacing

How is namespacing an issue?

Well I like semantically encapsulated code, not having a 3 page tooltips display, for instance. It's also a good hint to the reader what's used where and how.

Ok. I don't see how any of that is complicated by using function pointers in structs.

see

Let me make it real clear for you, this is how a method works in C++.

struct object{
int x = 0;
void add_to_x(int a){
x += a;
}
};

You call it like this:
int main(){
object object;
object.add_to_x(5);
return 0;
}


This would be the equivalent in C:
struct object;
void add_to_x(object*, int);

struct object{
int x = 0;
void (*add_to_x)(object*, int);
};

void add_to_x(object* o, int a){
o->x += a;
}

int main(){
object object;
object.add_to_x = add_to_x;
object.add_to_x(&object, 5);
return 0;
}

You could probably come up with some macro magic to make some of this go away but it's still clearly less convenient.

Not polluting the global namespace is a big one, as well as removing the need to reference an object in every associated function. The function could be made from within its struct, removing the need to reference and deference the struct just to access its members.

Are you trying to tell me that a C++ compiler isn't writing a function somewhere in memory then taking the address for that function and assigning it to some function pointer in a "class" [spoiler]struct[/spoiler] which just happens to have a syntactic access mechanism which is similar to a defined function rather than that of the dereferenced pointer?

Don't care about compiler magic, I make human-readable code.

our thread mascot

Attached: shi.png (2015x2204, 704K)

That's exactly what it's doing, what's your point?

That it's all just personal preference at this point and arguing about it is pointless.

Whether or not using classes is better than just passing struct pointers to a function is preference.

C++ handling functions designed to be called within a struct better than C is not preference.

Do you feel C as a language is also a meme nowadays or is it still a good language to learn in the beginning of your venture into programming?

I'm definitely more interested in "mid-level" stuff and possibly systempenetration rather than webdev.

This, not to mention the fact that what you wrote might still have some sort of issue with it even if it's semantically correct and works well. Usually you'll end up having to fire up valgrind to figure out if there's any retarded issues you're not noticing because they aren't as immediate.

Shit like calling
struct tree_node *root = malloc(sizeof(struct tree_node)*TREE_SIZE + sizeof(struct tree_node *))

And needing to zero-out the allocated space because the kernel doesn't allocate it contiguously and instead just assigns memory that's available on the heap and then needing to properly free up the memory allocated which becomes harder to do when faced with the task of implementing a more intensive data-structure.

There's an idiomatic saying in the C programming language that if your code is readable, it isn't efficient. Since many of C++'s functionalities have already been taken care of with optimized code, you have the privilege of being able to write code that is far easier to read and is very explicit. That is not to say that you can't define macros and other variable names to be understandable, but there are a lot of rudimentary tasks that, when fully optimized, make no sense at all if it is your first time reading C code. The language is great, don't get me wrong, but when your project becomes larger and larger, the practicality of building it in C really diminishes.

C++ is great in a lot of ways, and when used properly, its performance will be nearly the same with the slightest margin of error. You have an easier time doing a lot of things, as they are taken care of for you, however you have the opportunity to alter their behavior. That being said, it's not exactly a language that you want to build something in until you know HOW to build it. If you're working on an experimental algorithm, it's better to build & test it in Python, before developing it in C or C++

Attached: 30 year old boomer.png (380x349, 70K)

>and when used properly, its performance will be nearly the same with the slightest margin of error
C++ can potentially be even faster than C when used correctly: additional information for the compiler, better const correctness, move semantics and the like all enable ghe compiler to further optimize your code.
This doesn't mean it will, but it can, and often does.

inb4 muh linux is written in (non-standard) C you just suck

This is exactly what I was talking about in my reply in
C++ is by no means slow, however a lot of things are simplified in the language, and it is made debatably more powerful with the advent of templating. In essence, many of the semantics and details of lower-level operation are taken care of for you so that you can focus on producing extensible, generalized but fast and efficient code. Writing C++ as though it were Java will only give you a program that runs as fast as Java

>C++ can potentially be even faster than C

Yeah this is definitely true, it really comes down to how efficient your code is written, how much you ensure that every part and detail is getting as much use as it possibly can. I'm personally someone who gets uber autistic when writing C & C++ and not giving a fuck about readability except for the verbosity of variables.

However if I need a language where people can actually understand my thought process and what I'm doing, I'd rather just use Python, as it strikes the perfect balance of verbosity vs. simplicity. Easy to read, easy to write, and easy to improve and not have to deal with very tiny details that might cost you a couple hundred microseconds less on average that you wouldn't notice unless it was dealing with large amounts of data. This is really where C code becomes ideal; not in some 18 year old zoomer's gaming rig (as in stuff that he writes, not what goes under the hood lol)

Exactly the sole purpose of C at this point is for legacy reasons. Its replacements are superior to it in every way, save for less people knowing how to use them.

I use C as I want to understand how things work and don't trust that 'smarter' developers will do things correctly and/or not put backdoors into the output.

>There is zero reason to start a new project in C nowadays.
I disagree. My library project is written in C because it's easy to link and maintain binary compatibility with higher level languages, should anyone bother to make an extension.

>Exactly the sole purpose of C at this point is for legacy reasons.
and still, C will be used long time after your basedlanguages like rust will be long forgotten

OOP as implmented in C++ uses function pointer internally. member function have a hidden 'this' instance variable added to the start of the parameter list

If you don't want to polute the global namespace, just use the C static keyword to make it local to the compilation unit instead

FYI, C++ code is objectively more difficult to read than C, as C++ is a near superset of C

Calls through function pointers encounter overhead compared to regular function calls and I'm pretty sure most compilers, even today are still unable to inline function pointer calls. So there's quite a large loss in performance, especially for minor functions.

>live in France
>decide to read the book in its OV
>get dirt cheap opportunity from ebay
>shipping from California
>that was in july and never received it
why live

Attached: 1430409173388.jpg (364x350, 18K)

No No No, function pointers are shit slow (un-inline-able) and all the compiler does is insert an extra variable into the function call which is a pointer to the object. They can be viewed as free functions essentially but the compiler prevents you from calling them as free functions unless their declared as static within a class.

>inline function pointer calls
what did he mean by this

I'm saying if you call a function via a function pointer, the compiler can't inline your function, that's all.

He means if your source code invokes a function via a pointer the compiler can't replace the invocation with the body of the function as an optimisation. This problem is a large part of why OOP code is slow.

That is exactly the reason why there's little ambiguity in C++ code, you have a large depth of features and ways to express yourself.

hello fellow stuct packer

>they aren't quite alike

>The C Programming Language (The C Programming Language)
The C Programming Language.

Attached: Revolver_Ocelot.jpg (800x559, 35K)

non-virtual methods can be inlined just like normal functions

And for the same reason Cobol programmers are still in demand.

You are free to present an actual argument any time

If you can avoid using a virtual function, you can avoid using a function via a pointer. The advantages of namespacing can be achieved with less code using static functions.