Trying to learn C
By - Vercidium
Go straight for Microsoft Word
I think as a beginner he should write it on a stone tablet using a hammer and nail. That will really help op get a hold of the syntax. He can scan the code using Google lens and run it.
Hook up a stationary bike to your computer. Every full rotation forward inputs 0 and every full rotation backwards inputs 1; your handbrake backspaces the entire byte.
Backspaces will help op rectify his mistakes. That isn't good practice for beginners as they might get used to it and be relient on using the backspace. Hope you understand.
Every backspace spanks your ass with a paddle. May start off kinky but you get over it quickly and suddenly programming quite literally becomes a pain in the ass.
Why do you keep invoking a function called harderDaddy?
Username checks out
Fucking triggered. I had a math teacher that didn’t allow erasers. If you made any mistake you had to start from the beginning. She would rip the eraser out of your pencil.
This is the worst fucking approach to learning, much less math, I have ever heard. Mistakes are important to the learning process. Students fear it enough thanks to the way the school system is structured, no reason to crank it up to 11.
She probably didn't understand it correctly. We had something similar, but we were supposed to not use erasers so she can see our learning progress when it came time to hand in the notes of the past few weeks. When we made a mistake we were supposed to cross it out instead of erasing it. This was so she could see what we did wrong and how we tried to fix it. It's quite common among teachers that like to go the extra mile actually.
I had a couple of professors who did that. That's different from making students start over from scratch when they make a mistake.
Math teachers have a lot to answer for. Mine was a drunk. He'd regularly show up to class smelling of beer after lunch. After I left school, any time our paths crossed in local pubs he'd loudly call out my name followed by "typical underachiever".
Wow at least she was generous with her OCD
stationary bikes come with brakes?
[Why Microsoft Word is the best IDE for programming](https://www.youtube.com/watch?v=X34ZmkeZDos)
Nah nah nah nah, what am I made of, money? Word pad for the low income homies
Notepad might be better
C is for Confused
C++ is for C++onfused
nah that would be for [D](https://en.wikipedia.org/wiki/D_\(programming_language\))
I’m somehow surprised, but not surprised that that actually exists
D was C++11 before C++11
now it's "Rust 0.1alpha"
it just wasn't lucky enough to work on its own
Nah, C++ is post-incremented. You might be thinking of (++C)onfused…
C# is for C#onfused
Or for D♭onfused.
Or for B𝄪onfused.
My mind was blown when I learned that C# was supposed to look like C with 4 +s
I dont believe you
I'm a beginner learning C#, it seems pretty straightforward to me.
C# is Microsoft's answer to Java ultimately. So yeah, a completely different thing than C++. It's also IMHO pretty great.
He’s not confused, he’s merely feeling undefined behavior
R is for Rough
JS is for Jerma Sus 😳
He died for our sins
So you don't have to.
Nah he died of ligma
`char * const (*(* const bar))(int)`
This isn't even my final form!!
everything changed when the function pointers attacked
Just glancing at this gave me PTSD from my days programming C
I legit thought I was ready to attempt grad school this year but then that reminded me It’s not worth going back.
I went through grad school without using C. You can still do it!
Legit some of the worst days of my life were caused by CS college projects + procrastination haha. Nothing is worth doing that again!
May your signals all trap
May your references be bounded
All memory aligned
Floats to ints rounded
Non-zero is true
++ adds one
Arrays start with zero
and, NULL is for none
For octal, use zero
0x means hex
= will set
== means test
use -> for a pointer
a dot if its not
? : is confusing
use them a lot
a.out is your program
there’s no U in foobar
and, char (\*(\*x())\[\])() is
a function returning a pointer
to an array of pointers to
functions returning char
What is bar?
If you ever need help, [here's a tool](https://cdecl.org/?q=char+*+const+%28*%28*+const+bar%29%5B5%5D%29%28int%29).
Being honest, I used it to respond to him because I was as lost.
The trick in C is to always read the type right-to-left. Still can be tricky deducing function pointers tho
I think the actual rule is inside-out in a spiral, but in most cases that corresponds to right-to-left. Also, east-const helps when reading types in this manner, specially when it involves pointers.
int const* // pointer to constant int (you can mutate the pointer)
int *const // constant pointer to int (you can mutate the int)
The inside-out spiral thing comes up usually when there are parentheses in the type.
I'd like one that works in reverse
It actually does, but you need to be very precise in your description
http://c-faq.com/decl/spiral.anderson.html this is by far the best explanation I've seen for how to decode C types in case you want to check it is. It's short.
An array of 5 pointers to function pointers of int returning char \*const
`typedef char *const (*fn_ptr)(int);`
If I am not mistaken this is a *pointer to a const array* of 5 pointers to functions taking int and returning a pointer a const char.
The declaration with the typedef factored out should be `fn_ptr (*bar)` (disregarding `const`s).
Edit: yep, the website tool thingy agrees.
Edit 2: Read the reply.
Wouldn't it be a const pointer to an array of ...? (Also returning const pointers to char.) Or am I misremembering the direction of the spiral rule?
EDIT: looked it up, I was right.
If you have a `const int *a` then something like `++a` is perfectly legal, it is just that `++*a` (mutating the int) is disallowed (still unfortunately compiles but is undefined).
Are you sure you're replying to the right person?
I was thinking to myself “is that 5 index arbitrary” but then I realized after reading your comment that of course not, it’s C
Because  at array declaration means 5 elements.
That's the name of the variable.
I mean in 99.9999% of the time in c you never have to write that
And if you have that line in your code, you shouldn't
As if thats any different than the rest of my code
I use C because the java garbage collector deletes my commits.
Still, while C is a great langauge, its type notation is quite garbage
.... did you tag golang on accident then?
So those * are all multiplications, r-right?
Only on Wednesdays
What about leap years?
We don't do those here. We're programmers.
Don't forget time zones
These are easy to decypher. You just need to use the spiral rule.
That's where I go into an alcoholic spiral when encountering such things in my code.
Please, tell me this is true. 😂😂
Yep haha it wasn’t the reply I expected
C is one of my favourite languages along with its brother C++, I really hope u overcome ur confusion and learn to program in it.
I too am a masochist
Now I program on C (pure C) as a job so at least it pays off?
BTW how do you put many traits in this subreddit?
On the right hand side, under "About Community", click the down arrow next to "Community options", then "Use Flair Preview" should have a pencil symbol next to it for editing.
Those are the instructions for desktop anyways. If you're on mobile you're on your own.
It only allows 1 selection as far as I can tell
Edit: I ended up doing a cut and paste each time I added a new one
The radio buttons are fucked. You have to trick it into doing what you want. The little smileyface in the textbox should give you better luck.
Funny that the flare for r/ProgrammerHumor is buggy as hell :P
It's not a bug, it's a feature!
It’s a filtering mechanism!
surely by pure C you mean holy C
HolyC has some pretty interesting features tbh. Its compiler is whack and is basically embedded into the operating system. I'd like to see some of Terry's work become a reality
Was that this TempleOS thing by that psycotic engineer?
Schizophrenic, not psychotic. He knew computation down to the assembler and actually made HolyC because he thought that normal C was too high level (and he wanted to better integrate the language into the operating system). As he went on not being helped, his schizophrenia got worse but he remained rather lucid while doing anything related to programming (so scary). He was also known for holding some pretty strict standards in his OS, like absolutely refusing any graphics other than 640x480 16 color.
Schizophrenia is the name of the disease process characterized by psychotic symptoms. You can have psychotic symptoms without being a schizophrenic, but I don't think you can be a schizophrenic without having psychotic symptoms.
I see what u did there...
How prolific are C jobs?
I had a C++ job many moons ago, when I called myself a real programmer and thought of myself as an expert. Now I have accepted that I'm a perennial beginner and enjoy the crutches of dynamically typed languages. But I would like a new challenge.
When there are a ton of jobs posted for C++ with a bunch of expectations to go with them - that should tell you something.
Yes there are a ton of C++ jobs - every single time you’re going to end up working in a giant pile of steaming s***. People don’t age out of good c++ code bases - but people sure as hell bail on bad ones.
There are fewer C jobs for sure - but you generally know what you’re going to get - and it’s never as bad as what you end up with when you take a C++ job.
The C++ job came with me some decent dev tools and they put all their crap behind an api. And it was a small team so I had full access to senior devs. I was building front-end silly little apps for sales pitches to show off our 2D graphics engine. So it wasn't bad. And I was building new instead of working on other people's mess.
To add to what others have said,
Yes, C jobs are almost entirely embedded development now.
No, it’s not all maintaining old projects with crappy development tools.
Embedded software development has been progressing just like application and web development has and modern dev tools are about as robust as possible given the context.
Many embedded systems come with a 1st party IDE and support for other popular IDEs through 1st and 3rd party tools and plug ins and have runtime debugging tools just like any other.
It’s definitely not for everyone though. You’ll definitely have to worry about the resources your program is using and you will almost certainly have to use hardware test equipment like oscilloscopes.
If you’re interested in seeing what it’s like you should check out some of the popular MCU dev boards.
There’s a *ton* of different STM32 dev boards. The Nucleo ones have headers compatible with arduino peripherals so you’d have lots of cool things to mess with
ESP32 is new and lacking on 1st party development tools beyond software library and compiling/flashing scripts but it has Bluetooth and WiFi on board and is very popular with hobbyists.
PSoC 6 is less popular but it’s used in industry a lot and has a solid software library, 2 processors on the same board that share one memory space which is very interesting to develop for, and programmable digital and analog blocks that let you implement a lot of features directly in hardware.
Edit: and I’ve also had absolutely 0 problems getting well paid positions doing interesting work. In my experience there is *much* more demand than supply for skilled embedded engineers at all levels.
Totally non flamey question, just out of curiosity, have you looked into rust? I hear great things about it, from a lot of friends with strong c backgrounds.
No I have not, but I should. Haha
Well, even if you don't stick to it, it really helps you to understand many of the concepts behind other programming languages. And you'll know what to like about them (and maybe also what's not so good).
You'd only be a masochist if you stick to it :p
(ok, honestly, maybe at some point I'll come back to C and C++, we'll see what the life brings)
There's something so satisfying about writing something in C.
I know right, who *enjoys* writing in C++?
I like the simplicity of C, with functions, data structures, custom type defining, pointers (and function pointers), etc. you can do a lot of things, almost everything u need, and that's appealing.
On the other hand, I like how, based on that, c++ created a much more complex language with a lot of the modern features we deem essential but u can always notice the "translation" into the simplicity of C, and it's pretty nice.
I think both are real good "school languages", if you want to have an integral knowledge of how computers work, how the processor works and such, C and C++ allow u to learn that interacting with it (stack, program counter jumps, caching, alignment in memory...). C++ is also a nice school about compilers, being such a complex language (with a hell of compiling errors), u can learn a lot of concepts just "fighting" with them: r/l values, inlining, reference and value, the difference between compilation, linking and execution time, constant correctness... and I think that, if you are going to be an engineer or program something somewhat "low level", u need to have some idea about it.
That being said, I am not a fan boy and I can appreciate and love how useful other different languages like Python are for prototyping, AI and such or how Java is very robust when u need quick developing and compatibility but can't afford many errors so u need something that can go from a OOP design to real code with guarantees in short time.
C is a language that gives you all the tools and whatever you do is up to you. The language won't stop you from doing stupid things. It's you're responsibility, your fault, you're the one who's supposed to know what you're doing and what you want. Whatever you do you'll know how, where and why, because YOU wrote it.
Newer languages take you by the hand and walk you through the whole way. No, no, you don't want to do that, it's dangerous. No, you meant to spell it this way. I'll take care of the memory mess you've created, don't you worry about it. New functionality? Don't worry there's a library somebody implemented and made public, just use it, no need to know how or why it does what it does.
I used to have faith issues about convincing a rock through electricity to do things for me but at least I was telling the damn rock exactly what I wanted. Now the faith even extends to my instructions as they are handled by some other unknown entity.
Not crapping on any language, ultimately it's all magic.
I used to have similar thoughts about C/C++. I just want the damn machine to do what I tell it to do. But that changed after working on enterprise java product... Now, all I want is that the engineers will write more readable and less smart code so everyone will be able to work on it. Because not everyone is brilliant developer and sooner or later you will end up with smart parts tangled with spaghetti mess. It's better if a language is designed in a way that (more or less) prevents this. But for projects developed by single person? You should use what feels best for you, I don't care.
I think that works for school projects or whatever you won't ever touch again.
Every other piece of code YOU wrote you'll come back and think to yourself: "*wtf was I thinking? Evidently I wasn't*".
Code obfuscation is great for bragging rights but you're shooting your own feet in a professional environment.
The environment for C/C++ is the easiest part of it.
All you need is a complier and they are all backward compatible.
It's everything else that's the issue.
gcc, gdb, vi and man
What else do you need?
And some makefiles
Real men press up on the command line until they find the last time they used the five line long compilation command
Why would you do that if you have your punched cards?
Because he's learning C not FORTRAN.
set -o vi
then you can search for the compilation line in your history
CTR+r works regardless
fzf is your friend
And if you finally master them: cmake, so you'll appreciate it.
Coming from something like python where your environment is everything i can see why there would be some shock. Write a text file, run gcc, done
No poetry, pip, requirements, folder structure, etc etc.
Okay, sure, but those are the price of high-level languages/abstractions. Do you really want to manage memory and garbage collection yourself?
When I am doing microcontroller/embedded level stuff, the ability to know what every bit of memory is doing is extremely useful.
Exactly, it depends what you are doing.
I'm not knocking it, it's certainly gotten easier, only saying how it could be shocking for someone
Valgrind to detect memleaks.
I remember being so excited when I started to use valgrind for memory leaks
Once I was doing a project and the memory management was so bad that when I ran valgrind for the first time it crashed my computer.
That thing absolutely saved my sanity in operating systems class.
gcc, gdb, vi and sir
what else doth thee needeth?
^(I am a bot and I swapp'd some of thy words with Shakespeare words.)
Commands: `!ShakespeareInsult`, `!fordo`, `!optout`
And sir! 😂
I'm adding this to my .bashrc
"consult the sirpages"
VS Code. Maybe CLion? Code::Blocks is okay for beginners.
If you're not using Scratch, you're doing it wrong.
For anyone starting, I personally recommend VS community. I started with it and it has a very solid debugger already set up, so figuring out what ticked and how it ticked was much easier as a beginner. Because we all love printing "hi" as a debug option but when the core starts getting dumped you're a bit screwed.
VS code also has a great debugger but you have to set it up a bit which can be challenging to beginners, even with a guide.
The disadvantage of VS is that it's Windows only, unlike VS Code.
Basically this. If you compile with MinGW and makefiles, you can easily (relative to C standards) make your project cross platform.
Use clang instead of gcc, especially helps beginners with much clearer error messages. (assuming that hasn't changed much in the last 10 years :D)
It has changed somewhat. Clang is still better though.
Sometimes I miss the old TurboC days
TurboC++ was greatness
Glorious blue background
I started with Turbo Pascal in 1983 and then moved on to Turbo C and C++ and even Turbo Assembler. Those were good days.
C and C++ are great until you need to depend on third party libraries.
On Linux just pray your package manager has them. Then its easy.
If you’re using cmake you can also just pray that they’re using cmake as well.
I have heard of that feature, how does it work?
CMake is a 'meta build system'. Normal build systems tell your computer how to compile your code, exactly down to the last bit; these include Makefiles, Visual Studio solution files, Xcodeproj files, etc. These are difficult and tedious to edit by hand, so with CMake, you simply say 'okay, generate this executable with these source files with these libraries linked in', and it does it for you.
You can then proceed to generate *any* of the above build systems, and *then* compile your code. It makes writing cross-platform C/C++ quite a bit easier.
There's a new build system called Ninja, that actually *explicitly* advertises itself as *not* meant to be directly created/edited by hand, but instead generated using stuff like CMake, for instance. You can even integrate your testing code with CTest, which is a part of CMake.
My development environment now has been shuttling between VS Code with clangd/C/C++, and CMake, and CLion.
Reimplementation is the C way!
You're doing it, son! You're doing it!
Just install the C/C++ extension in vs code and install gcc or clang. Or just open VS for C++ and save the source files as .c
If you're starting out, gcc might be better than VS imo. The MSVC compiler's error messages are a lot more verbose and cryptic than gcc's.
iirc you can set gcc as the compiler instead of MSVC in VS
Vs code is where it's at. That said... Vim or turbo c for maximum authenticity
it's so cute how you followed your dad into the business
I dream of talking to my future kids about projects
*Image Transcription: Text Messages*
**OP**: I want to start learning C but I'm confused about the development environment. Any tips on where to start?
**Dad**: That's correct. You're supposed to be confused.
^^I'm a human volunteer content transcriber for Reddit and you could be too! [If you'd like more information on what we do and why we do it, click here!](https://www.reddit.com/r/TranscribersOfReddit/wiki/index)
Why is everyone suggesting he learn in vim? That's means learning two things at once.
Use something comfy like eclipse or vscode.
If you’re not using vi in a terminal window you’re just doing it wrong. You don’t use an IDE for C!
Now get off my lawn you damn kids!
UNIX is the C development environment. Everything else is a puny imitation.
Dont give up. C together with Linux is the most satisfying and coolest thing there is in the programming world.
And also the most frustrating and error prone.
Only because it forces you to learn the fundamentals of Computer Science. Other languages gets you up and running quickly without you worrying about what happens under the hood.
Agreed that for most people that is all you need. However, if you are serious about learning CS and Engineering, learning C will be the best thing you ever did.
If you don’t understand memory allocation then you’re going to bad at C.
If you don't understand memory allocation at all, you are most likely going to write inefficient code in other langues too. Its good to learn that C memory allocation basics so that you will never have any problems in any other languages.
Just get clion, its a great way to get into the syntax without having to worry about compilation just yet
Not me though, only the end of my second week in systems programming my professor was already asking us to write a modular makefile and I almost shit my pants cause he pretty much threw us to the wolves not showing us a legit example first
Does require you to know a bit about CMake though. But yeah, +1 for Jetbrains. I use Intellij daily for Kotlin dev. CLion has been great for my C/C++ hobbies. But it does cost \~$20 a month.
Well you dont really need to know about cmake to get started, if you make your new class/header files correctly it configures everything for you. By the time you are ready to customize stuff you should be ready to move to a 3P compiler if you want..but great place to get started coming from high level for sure, even on linux it's pretty painless and good at shielding you from any vulnerable moving parts
Agree Jetbrains suite is definitely great for moving for language to language tho, I can switch from Android Studio to CLion and feel right at home with shortcuts. Abandon visual studio, rider for C#, they even have pycharm for you pythoners! i still have access to my old uni.edu email addy so I'm using it under a free student account still (shhh!!)
I mean, yeah that's true. You don't *have* to know CMake. It's helpful to understand the build systems though. I had to learn a bit about it when I was porting my Linux game engine to Windows.
Yeah, Jetbrains IDEs are really solid. Although, I do have issues with Android Studio, i.e. Logcat can just forget to output logs, test instrumentation crashes, intellisense will fail, etc. Despite the issues, I couldn't imagine writing Kotlin in anything else.
Lol, I was using my fiancee's student email for sometime. But after I started getting paid for my work, I thought I should be using the paid license lol. $20 for CLion isn't too bad.
I use IntelliJ for DLang for my pet project so I dont wanna get confused. I really only use kotlin for android development so I stick with android studio and pray the gradle build never has to update every again (it never works unfortunately)
java, I never want to use again, so it works out perfectly
Man at least you were taught makefiles. In my 1st year of uni we had a 2 semester programming module in C.
The prof wanted us to use Borland compiler from like 2005 and it was so horrible i didnt even install it and used gcc with vs code.
He also didnt touch on header files or compiling anything more than 1 .c file.
Guy was excellent with his teaching methods imo but a year later trying to learn how to compile bigger than one file c++ by myself is just pain because i dont know anyone that knows c++.
Also thanks for the reminder that clion exists completely forgot haha.
A C professor who didn't teach header files??
The development environment of C is one of the easier. You can find a C compiler preinstalled in all Linux/UNIX distributions, and it's easy to install on Windows or macOS, open a shell and type `gcc program.c` and you are done. You don't really need anithing else other than the compiler, at least for simple projects you can compile everything with one command. And if you need a library you just download the source code of the library and include it in the project.
In python you can "download the source code of the library and include it in the project" too. Pip is just a tool to get this code and link it.
In C it's the same, some IDE help you link it but it can be confusing at first
I'm learning C on vim on WSL right now
Best book on C with all you'll ever need to know (lol) is Kernighan && Ritchie's C Programming Language.
Dev environment can be vi, emacs, notepad, vscode, etc. :)
I sometimes use clion, but it feels like it's a bit much.
Wait till he discover GLUT in codeblocks!!
You're giving me PTSD lmao. I spent a year of my life from 14 to 15 trying to make something with codeblocks, freeglut, and SFML. I actually got somewhere but just gave up. Took me a week to build the same thing from scratch in C#/Monogame with no prior knowledge to the language lol.
I would argue you're not doing development at all if you aren't confused
I'm confused with learning web development. There's tons of software to use that you have to install and then when I finally get it all installed I have no idea where to go from there
It depends what stage you're at. If you're 100% new to web development, you make an html file and start there. If you're going from vanilla html/css/js to some of the major js frameworks then there's some setup involved but it's still (in most cases) quite minimal.
If you're using Windows, you could use Code::Blocks as an IDE. I mean of course you could just compile with gcc/clang/mingw like people have said in the comments, but since this IDE is free, lightweight and easy to configure, you could give it a chance, specially if you're just going to use C for academic purposes.
You can spend more time configuring in Code::Blocks than actually working
That’s the sign of a good editor for me
I used Dev C++ on Windows. It’s pretty good and simple C/C++ IDE for beginners. It even allows to work with separate files without creating the project.
BTW: this **vodafone AU** carrier feels for me like at home. On my iPhone it’s **Vodafone UA**. Now I use iPhone 11 but on my previous iPhone 6s I saw a Vodafone UA label for years 😄
If you're OK with windows, I recommend starting with visual studio. It has a free version, and as a single developer you don't really need any of the features from the paid version. It has a very good debugger, excellent code highlighting and code completion, and the project / solution structure is much more beginner friendly than messing about with makefiles. The default release / debug modes are also good enough for almost everything when you get started, so you don't have to mess around with compiler flags. It also has decent git and github integration.
C actually stands for “confused”
Development environment = vim and gcc have fun !
Why don't you just start with A and B first? :)
(Neo)Vim with some plugins + LSP is pretty cool, although you'd have to learn vim first.
I know some people who love CLion, haven't tried that out.
VS Community if you're only developing on Windows (can still target Linux through WSL thanks to cmake).
VS Code is also pretty great at C++.
Hail void pointers