/gcc/ - General C Circlejerk

Welcome to the first official /gcc/.
Talk about C and stuff.

>I want to learn C
Read:
C Programming: A modern approach
The C Programming Language 2 (aka K&R)
GNU C Reference Manual
Avoid like the plague: Learn C the Hard Way

>I'm ready for more!
Expert C Programming: Deep C Secrets
Computer Systems: A Programmer's Perspective

> How to write readable code
Linux style
OpenBSD style
Avoid like the plague: GNU style

C programmers please help me add to this list.

What are you working on?
What do you use C for?


To foster some discussion:
One major complaint about C is it not having separate namespaces. How do you work with this? Do you use any sort of file organization or segregation schemes to keep symbol collisions in big projects?
C is a very low level language that is best suited for groundwork, do you use any layering on top for more "high-level" programming? eg. embedded languages such as lua/guile

Other urls found in this thread:

icube-icps.unistra.fr/img_auth.php/d/db/ModernC.pdf
twitter.com/NSFWRedditGif

Is K&R the best way to learn C for someone who only knows OOP concepts?

I'd suggest A Modern Approach instead.

Unless you learned OOP through Smalltalk, what you know as OOP is probably built upon the procedural model.
I think the main difference is that in the C model, you do not have different agents to which you "ask" to do things, but just the main program logic, which performs actions on objects.
so instead of something like
array.sortyourself();

you
sort(array);

For the rest it's pretty similar, you just have to "unlearn" some of the methodologies of OOP, eg stop expecting different agents to have their own logic.

If I'm not being helpful ask away and I'll try to make myself clearer

Is this Modern Approach book that people keep recommending available as a PDF from anywhere? Most books you don't even need to pirate; a PDF is usually the second or third search result anyway from some university's website.

Also, if I find an old edition, is it okay to read that one instead? I am exactly the sort of Pajeet hobbyist who only wants to learn programming until it becomes difficult and only look for a programming job if it turns out I can do it with no effort. With that in mind, if more recent editions of these books only include changes that are for very advanced programmers, I probably won't bother, same as I don't want to just start with C++.

Do you have similar guide for C++?

"Accelerated C++: Practical Programming By Example" is a book, and some user here made videos of himself reading and learning each chapter, so if you want some videos to help you learn, that's a good place to start.

>One major complaint about C is it not having separate namespaces. How do you work with this? Do you use any sort of file organization or segregation schemes to keep symbol collisions in big projects?
>C is a very low level language that is best suited for groundwork, do you use any layering on top for more "high-level" programming? eg. embedded languages such as lua/guile

How much time do you need between learning the language properly, building a respectable portfolio and getting a job. Above average intelligence guy, but not gifted. 4 hours a day.

I know, estimates, of course.

there are a few downloads at libgen.io

But if you want to pajeet, you probably don't want C, you probably want either of ruby, python or javascript.

Thanks, but I've done Python. I want to learn C so I can pick up hardware stuff too and learn actual computer facts about memory and whatever the fuck a socket is.

Does anyone have any experience writing 3D game software in C?

If i wanted to be a C zealot all the way, how long would it take me to actually put out a game if I only use SDL2 and OpenGL?

A socket is a UNIX object (though the winsock api somehow implements this on windows) which is pretty much:
A buffer stored in kernel for which a process has a handle and to which it can read or write
That's all a socket is really. But it's very flexible, a process can create a socket and bind it to a port (essentially: a unique number) to communicate to another process that has a socket bound to the same port.
The other process can be in another computer, in which case they communicate over a network (notably, the internet). This is handled by the underlying network stack. The rest of the process is done transparently.
After you learn your basic C, read beej's guide to network programming with sockets to learn more about this.
However, although sockets are simple, programming them is not quite so, because there are many types of sockets and several parameters you can use on them, so they look more complicated than they really are in C code.
Also I'm very sure python has socket support as well.
But yes indeed with C you understand things at a lower level indeed

probably 200 hours

What attracts you to C++

icube-icps.unistra.fr/img_auth.php/d/db/ModernC.pdf
Is this a good startpoint for beginners ?

Any start point is a good start point, you can always find something else later.

The ability to waste my time by optimizing the memory usage and cpu of programs even though they already perform pretty good.

Oh yeah I shaved off another 10 microseconds off that function that only gets called every 10 seconds. That feeling never gets old.

>What are you working on?
Java
>What do you use C for?
Maintaining old programs. Getting real tired of faggot """contributors""" fucking up my code because they don't know C properly.

>Avoid like the plague: GNU style
definitely

Should I learn C++ or C?

If you learn C, you'll hate C++.
If you learn C++, you'll hate C.

I already have java experience an am learning C++

Oh well

I still think you should give it a try.
Idiomatic C is very different from C++.
You won't ever have to "avoid" features because C has very few, and you'll end up using all of them if your projects balloon past 1000 loc.

Don't listen to him. Yes they are kind of represent two different approaches to programming, in the field of simplicity vs complexity
Start with C, because that's the foundation on which C++ is built.
You don't need to learn much about the standard library though, C++ has it's own STL, but be sure you understand the core concepts of C well and C++ will be a lot easier.

And yes I always say "Learn C then C++"

Looks good, it even touches assembly, which any self-respecting C programmer should know.
I'll add it to the next OP

>GCC also includes a go compiler
Loving it.

C+Go master race

What makes go worth using when it's literally a neutered C?

If I am building an application, I'd build the core engine written on C.

However for plugin system etc has to be written in an easily maintainable and much more productive language.

So the option is lua, python, perl etc but Go has a better performance.

C is yet to be replaced though. It has the best performance of almost all languages. However, scaling and implementing a large application without causing undetected memory leaks, overflows are a major pain in the ass.
Better option would be Rust (C++ done better) but learning Rust is hard, even for C++ devs. So for now I am stuck with C+Go, although I intend to be shifted to Rust+Go for a better and safer code base.

What's the problem with Learn C the Hard Way?

the author has his head up his ass and can't teach worth a damn

keep reading it if you want, you'll come to a brick wall about 20 chapters in because his teaching style is "copy all this code that i wont explain and then try to break it and tell me why it did that :^)"

As said, the author is a prick but more importantly, it doesn't really teach you, it just gives you a tour of what it's like but you end up with no solid foundation. You don't end up knowing the language or knowing how to solve a problem on your own.

Silly bratposter

if I know the syntax and basic programming logic to make a few hundred line projects with just the standard libraries
how the heck can i learn these giant libraries you seem to need for anything
its so much more complicated with like 1 million ''''objects''' and functions

c is like basketball with the hoops at pro height

you just hope the library has good documentation

What

>K&R

absolutely deprecated
use 21st century C (the 2nd edition)

Nope.

SAME SHOW

Kill yourself, my mate.

I'm fine with both

Both languages are completely different and there is no point in comparing it.
Learning C++ as C with classes is mistake.

If you want to learn C++, learn C++

>If you want to learn C++, learn C++
If you want to learn C++, don't.*
FTFY

>Rust (C++ done better)
Common Lisp is C++ done better

Why?

Is C Primer Plus a good book as well?

C++ is a terrible language, and should not be used for any purpose.

>One major complaint about C is it not having separate namespaces. How do you work with this? Do you use any sort of file organization or segregation schemes to keep symbol collisions in big projects?
To avoid collision between different functions you can use static and wrap all the functions in your .c file in an extern'd struct (basically a vtable). You end up with something like List.append(list, thingToAppend); You can also just choose to prefix things.

>C is a very low level language that is best suited for groundwork, do you use any layering on top for more "high-level" programming? eg. embedded languages such as lua/guile
Common Lisp has excellent FFI capabilities through CFFI on SBCL. There's also ECL which can also compile to C (Chicken Scheme can do this also).

Do you have any experience with C++11?

Have you been working on larger c++ project?

Learn C and write a lot of C first.

After you make large enough systems, such that you've started implementing your own object mechanisms, learn C++, preferably C++11 or later.

You'll understand much better when and why to use C++.

>To avoid collision between different functions you can use static and wrap all the functions in your .c file in an extern'd struct (basically a vtable). You end up with something like List.append(list, thingToAppend);
That's acutally a pretty good idea user! I'll implement it next time when it makes sense.

As for the low-level/high-level stuff, I am more inclined to use something like tinyscheme, which is a very small embedded language, as opposed to embedding perl or ruby.

Do you have anything to say about either of those things or are you just here to abuse the quoting system?

As an example of when it makes sense to use it, you can use it for API versioning by externing multiple structs with the same interface but links to different functions. You can also use it in the context dynamically loaded libs where you export the same interface through their structs so you only have to load the struct instead of loading all the symbols individually. This lets you reload and change functionality on the fly and you can combine that with another language through FFI to test your new rebuilt code.

Sometimes I get inspired to write very nice and very systemically correct C code, but then I actually try to do it and it becomes cumbersome and boilerplate.
How do you have fun writing C?

op is a qt girl

There are actually many interesting ways that C++ and Lisp are very similar. They share a similar view for what a language should be. Unfortunately C++ just executes it all very badly. Sometimes I dream of a language with the homiconicity of lisp and the low-level unsafety of C++

In Common Lisp on SBCL you can turn down the safety if you want and restrict the types so that it'll generate more efficient assembly. You can also do standard mallocs and frees.

I've found that the fun is clumpy. When I write C, the best parts are refactoring and watching how fast it goes. To me, the sense of accomplishment at the end is the feel-good funness.

Writing it is kind of a pain.

>Linux style
>OpenBSD style
>Avoid like the plague: GNU style
Is there a specific comparison between the three?

Practical C Programming is pretty good. Although I'm coming from java.

*general C++ circlejerk

Thanks user