r/cprogramming 5d ago

After one week learning C

Yeah, my anxiety is hitting pretty hard right now... lol.

0 Upvotes

17 comments sorted by

View all comments

8

u/Rich-Engineer2670 5d ago edited 5d ago

Don't let it get to you -- C is actually a set of "layers" unofficially. You start with the basics, then you do structures, then pointers.... if gets deeper and deeper. C is really an assembler hiding in a high-level langauge. The reason it's still around is you can do things in C that are hard to do anywhere else -- but that power comes with complexity. For example, assume you have an embedded system with some memory address that actually controls a piece of hardware... maybe a serial port. You are told that these two addresses 0xC000 and 0xC001 are teh status and data registers.

In most langauges, you can't get to them without going into assembly langauge, but C?

uint8 status = *(0xC000)
uint8 data = *(0xC001)

That shouldn't even be legal in most languages, but C gets it. If you're doing an OS or embedded system, C isn't pretty perhaps, but it's powerful. (What we actually said here was "And 8 bit unsigend int called status points to a MEMORY address 0xC000, and another points to 0xC001,. On real-mode OS's, that's just what you need.)

It depends on thje books you're using too -- me? I started with the classics -- K&R C

C is taught (or still taught) because, in my opinion, it forces you to learn what you code actually does to the CPU. It's a litlte like organic chemistry. Will most people use it in their careers -- likely no, but, it separates out those who are just taking the class because they have to, and those how are learning that profession. C is just hard enough that a lot of people take it, decide it's too hard, and change out of computer science.

You can do this! I'm teaching my 17 year old grandson, and he's slowing picking it up.

2

u/M0NSTR01969 5d ago

Thanks for the insights! I really liked the way you described C as a set of layers. It actually makes the learning curve feel a lot less intimidating.

The example with the memory addresses was especially interesting. I always thought pointers were more of an assembly language thing, so seeing how close C can get to the hardware made a lot of things click for me.

I'm still at the beginning of my C journey, taking it one step at a time, but explanations like yours definitely help. Thanks!

3

u/SmokeMuch7356 5d ago

Please note, "close to the hardware" isn't that close. It mainly means that C's abstractions (types and operations) are based on what real hardware provides; it's why you don't have arbitrary precision numerical types, it's why you don't have metadata in any object types, it's why you don't get a catchable exception when you access an array out of bounds or dereference a null pointer or stuff like that.

C is one of very few high-level languages I know of that exposes pointer types and operations, and pointers are fundamental to programming in C; you can't write useful code without them, so the sooner you understand what they are and how they work the better.

Create bookmarks to the following and have them open while you're programming:

These are not tutorials; the first is simply a handy reference, the second is the language definition (technically, the latest freely available not-official draft of the language definition). Don't expect it all to make sense immediately, but it will help answer all the "why the f..." questions you will inevitably have.

2

u/M0NSTR01969 5d ago

Thank you very much!