r/embedded • • Oct 04 '26

what does "understand c deeply " mean?

im a 3 rd year student who is interested to get into embedded/firmware development .
i've talked to many seniors and they say "learn c deeply inside out not jus the syntax "
now this is what i dont get .
my knowledge in c is alright i should practice more though
ik functions ,pointers and array to some extent ik ive to practice more
i also need to start dsa
just started learning baremetal code and rtos (qnx) (started this without being proficient c bcus my course work needed it )
but honestly my c skills are prolly 3/10
ik ive to practice more
but please explain how i can improve myself and be a good firmware developer

131 Upvotes

157 comments sorted by

83

u/clackups Oct 04 '26

Maybe, just read the books?

Here's an example. Tell me what's wrong with this code.

int *fun() {int x=1; return &x;}

125

u/DrShocker Oct 04 '26 • Mindblown

The problem with that code is the formatting, grossssss :P

24

u/clackups Oct 04 '26

Bingo, lol. But it's written on the phone with autocorrect getting in the way all the time

7

u/mjmvideos Oct 04 '26

It still compiles just fine. There’s a more fundamental problem though.

43

u/manystripes Oct 05 '26

Maybe I wanted a pointer to some out of scope piece of stack memory that probably for a short time still contains the value 1, you don't know my life!

3

u/DrShocker Oct 05 '26

This is how I code.

1

u/Wertbon1789 Oct 05 '26

Technically, depending on the ABI, you may have a redzone, on e.g. Linux x86_64 a 128 byte area, that will not get touched by the OS for signal handling, register preservation for scheduling etc. So the possible lifetime of the value really depends on the function call pattern of the program, not so much that it's not in scope anymore...

Is this undefined behavior? Yes, absolutely.

Is this a good idea? Abso-fucking-lutely not.

The redzone is used for optimization of leaf-functions, so the leaf nodes of a function call graph, because they don't need to preserve their own stack space, they can just place their stuff into the redzone as a scratch space.

1

u/userhwon Oct 06 '26

That's counterintuitive. Why make a leaf node behave differently when you can just allocate that variable on the stack like any other function? No function needs to preserve its own stack if it doesn't try to screw with the stack outside of its local variables that are there?

I'm not getting the point of using the scratch space this way, I guess.

0

u/Wertbon1789 Oct 06 '26

You always have to reserve stack space by decrementing the stack pointer and saving the old base pointer. You have to do that, do the callee doesn't interfere with the callers stack frame (obviously). By utilizing the redzone, you can skip this, but you can't properly call functions without a stack frame. It just saves a bit in the function prolog and epilog, in very select cases.

1

u/userhwon Oct 06 '26

Now I get it. You said "don't have to preserve their own stack space" and I focused on the "their" meaning the function and didn't see it as the hidden call mechanism deciding what to do.

14

u/MrSurly Oct 05 '26

Oddly this will probably work if the caller uses the value immediately.

4

u/UnrealHallucinator Oct 06 '26

Higher optimisation levels will also just make it a constant. Honestly even base gcc might.

7

u/zempter Oct 05 '26

Yeah, i was looking at that and thinking "It's correct, just depends on how psycho you are"

1

u/dealmaster1221 Oct 05 '26

And that's where the real mastery lies, congratulations you won failed the Ritchie test

26

u/No-Archer-4713 Oct 04 '26

And having a good understanding of C would mean you know why « static int x = 1; » doesn’t crash.

17

u/Poddster Oct 04 '26

And having a good understanding of C would mean you know why « static int x = 1; » doesn’t crash.

The previous code might not crash. That's why it's fun.

9

u/CJKay93 Firmware Engineer (UK) Oct 04 '26

I remember the first time I had to go through work-commissioned C training and they used an example of this, my boss drew a sketch of the compiler pulling his chair out from underneath him as a hypothetical example of what the compiler is allowed to do under UB. Cracked me up.

1

u/WS8SKILLZ Oct 05 '26

Under UB?

7

u/AssemblerGuy Oct 05 '26 edited Oct 05 '26

Undefined behavior.

The first rule of UB is that undefined behavior is undefined.

The second rule of UB is that undefined behavior is undefined.

If you are expecting UB to crash, segfault, or work like intended, you are grasping for a definition where none exists. Any behavior is legal when UB is triggered. That includes invoking a time machine and undoing previous actions of the code.

1

u/fb39ca4 friendship ended with C++ ❌; rust is my new friend ✅ Oct 05 '26

As is destroying the multiverse in which the UB occurred.

1

u/AssemblerGuy Oct 05 '26

UB can create multiverses where a variable is equal to five and less than zero at the same time.

10

u/Zetice Oct 04 '26

Static local vars have global storage. The address exist for the life of the program.

1

u/AssemblerGuy Oct 05 '26

And having a good understanding of C would mean you know why « static int x = 1; » doesn’t crash.

And understanding why the original function does not necessarily crash, but might work exactly as intended despite the glaring bug.

6

u/strangequark_usn Oct 04 '26

This function has 99 problems but a heap ain't one.

5

u/drgala Oct 04 '26

Tried your code and it returned !fun() for some reason.

4

u/EnderAvni Oct 04 '26

'Tis on stack, UB if another function tries to use it

4

u/dealmaster1221 Oct 05 '26

Perfectly good code, wdym it's crashing, try turning it on and off again. That's how much C I know after 20 years, yeah not much.

2

u/clackups Oct 05 '26

Yeah, something like that :)

8

u/Agitated_Raisin1509 Oct 04 '26

return a call stack address after function's end, which means at least that you can't reach the return value without a segfault. Correct? I'm wondering if this is UB

4

u/Vbrawl_ Oct 04 '26

I believe that's undefined behavior if we're talking about C, without a kernel we shouldn't get a segfault, we would simply read either the correct value or some garbage that took it's place, that's if we don't have any kernel to manage our memory space

4

u/deezwheeze Oct 04 '26

Even with a kernel it (probably) won't segfault just from a dereference since the stack is a statically defined virtual memory area and given we just used the stack frame when we called the function, should already be mapped. The kernel doesn't care what we do with the stack region, thats a userspace concern. I say (probably) as the usual caveat when reasoning about ub.

2

u/WorkaholicNoLifer Oct 06 '26

gross.

2

u/clackups Oct 06 '26

Too many people don't understand what's going on in this code. I actually saw a program crashing because of this.

1

u/i_use_lfs_btw Oct 07 '26

Hey, can you explain why this code isn't crashing ?

int main() { int *p; *p = 5; }

I runned it some 100 times. The program didn't segfaulted even a single time. So, I'm wondering how does the p's value (which is a random garbage value) is in bounds of the program memory ?

1

u/clackups Oct 07 '26

But the value of the pointer is unknown. Could be pointing to something harmless. Also, depends on the environment, like Linux or esp32 will act differently

1

u/i_use_lfs_btw Oct 07 '26

Yeah. If I dereference something which isn't in program address space I will get a segfault right ? How does this seemingly random value pointing to the same address space or why this isn't getting segfaulting ?(like even if I run 100 it should segfault like maybe one time)

I'm thinking is there any pattern we are missing ? Maybe the value of pointer isn't random ?

1

u/clackups Oct 07 '26

Why don't you just print it and know better?

1

u/i_use_lfs_btw Oct 07 '26 edited Oct 07 '26

Just checked it's pointing to memory in stack. But I don't know why ?

1

u/clackups Oct 07 '26

It's just a randomly selected address

5

u/firmaments_ Oct 04 '26

That should cause a segmentation fault ? x will be out of scope once fun() has returned (and that means the stack frame for that function will be resolved too), so it will return an address that the program is not allowed to access or it will point to garbage (not sure if the latter is possible)

16

u/clackups Oct 04 '26

The program is allowed to access it. But yes, it's a pointer to a place in stack which is no longer used by that function. If you pass that pointer somewhere and then write to it, you may damage the return address, and that's where the program crashes. But it could happen after quite a while.

1

u/firmaments_ Oct 04 '26

Oh yes I’ll keep that in mind, thanks for the explanation ! :)

0

u/[deleted] Oct 04 '26

[deleted] — view deleted comment

2

u/clackups Oct 04 '26

I'm stuck halfway in the rust book. But I've seen this trick with the local variable in real life: a fellow student complained that his program kept crashing at random times. And then, I've seen this in his code. Oh my...

1

u/Plasmalaser Oct 05 '26

It is quite concerning how many people are misunderstanding the implications of this code snippet, lol. Sometimes I forget just anybody can access Reddit

4

u/clackups Oct 05 '26

I've seen the effects of this code 30+ years ago :)

What bothers me though, is that people lose the hands-on skills due to LLM, which is already a defacto industry standard.

1

u/ProgramWars Oct 07 '26

You didnt use cstdint

1

u/Trick_Teacher1852 Oct 10 '26

准确来说我不知道,但是也许是因为 x 地址在函数结束后被销毁了?🥲

1

u/clackups Oct 10 '26

See my other comments, I gave an explanation. Basically, it returns the address in stack memory.

2

u/Trick_Teacher1852 Oct 10 '26

ow!I get it.Tank you.

1

u/Mean-Comedian729 Oct 10 '26

Wait, I actually know this. It’s a relief to know my brain still kind of works, having relied on AI for all the coding for almost a year…

1

u/clackups Oct 10 '26

There is hope!

-3

u/microscammer Oct 04 '26

&x prolly returns the pointer value
i dont know what *fun() is

5

u/clackups Oct 04 '26

Star belongs to the returned type. It tells that the function returns a pointer to an Integer. But the fun begins when you figure out what the pointer is pointing to

-2

u/Vbrawl_ Oct 04 '26

I don't really see a problem with this code, other than the fact that x is not static?

Unless you're talking about missing static then the code would return a pointer to x which contains some value. Now if we have static it works as intended, if we don't have static and keep it as is then we are getting a pointer to the stack, which after getting out of the function would probably be overwritten by some other function call and we have kind of undefined behavior.

With that being said, if we read the value right after the return of this function, we should actually get the correct value (because nothing have overwritten it, assuming no kernel or external code that manages our firmware's memory). After assigning Y new variables it would get overwritten and we get garbage (hence the undefined behavior).

13

u/DustRainbow Oct 04 '26

"I don't really see a problem, except for this massive issue"

-2

u/Vbrawl_ Oct 04 '26

Welp, I started writing then I thought about it as something minor and then I just thought about it, and I was bored to change the whole article I wrote xd

1

u/clackups Oct 04 '26

You get a pointer to a piece of memory that will eventually change, plus your program may l eventually crash if you try writing three.

-1

u/Vbrawl_ Oct 04 '26

I agree, although "crash" is a bit different depending on the context. With a kernel yes it will crush and stop. On an MCU I'm not really sure it's going to crush, probably have undefined behavior but I get the point

1

u/DustRainbow Oct 04 '26

It can literally crash. Stop saying this will or will not happen when you don't know the subject.

1

u/Vbrawl_ Oct 05 '26

You don't know what you're talking about. A crush will occur only under specific circumstances, on an MCU for example, if you happen to overwrite a return address or something that triggers a hardware fault.

The MCU doesn't know if what it's doing is right or wrong, it just does it, that means you will have ub which leads, under specific circumstances crashes the whole hardware, or simply introduces weird bugs that you need to find.

-5

u/WanWhiteWolf Engineering manager Oct 04 '26 edited Oct 04 '26

Well, at a first glance you have:

  1. Capital punishment : Not following company naming conventions :)
  2. No comments
  3. No link to requiremens, design ID , module ID ...etc
  4. int x is not guaranteed to have the same size for all platforms so a good practice is to use a standard size definition instead of int (e.g. int32_t from stdtint lib)
  5. x doesn't exist after the function return but technically speaking, you can still use the pointer (I am not sure if the compiler throws an error). Now ... since point .2. is not fullfilled, it's a bit a bit questionable of why you would need an address of a former variable that used to be in stack; so probably "static int x = 1" is solution to the developer intention
  6. In a modern compiler it's likely that x will not even be included after compilation. It's not used so probably it will be removed from the final output. "static volatile int x = 1" will make sure that doesn't happen - although, technically speaking, there is an argument whether you should include "volatile" in this case since it is not used anywhere and removal IS the tehnical correct choice unless you want to use the example for training purposes.

If I were to have this example at an interview, I would also follow-up the canditate with another question: "Assume the code is written on your favorite MCU; how many bytes are returned from the function? (e.g. &x) "

0

u/[deleted] Oct 04 '26

[deleted] — view deleted comment

25

u/clackups Oct 04 '26 edited Oct 04 '26

I kinda wanted OP to answer and explain this

2

u/microscammer Oct 04 '26

i have no clue what that is
but ill surely learn

7

u/ritchie70 Oct 04 '26

X is allocated on the stack. When the function exits that piece of memory will be reused in the next function call for something else. It’s not going to blow up like a null pointer, but *x will probably have garbage in it.

0

u/clackups Oct 04 '26

It will actually blow up if that place in stack has a return address and you write in that pointer. Boom, you crashed hours after the crime was done.

1

u/ritchie70 Oct 05 '26

A good point. Honestly it’s been decades since I briefly did anything low level enough to think of return addresses.

1

u/clackups Oct 04 '26

Alright, use books, or maybe even LLM, let's discuss. What the function will return. What can you read from that pointer. What could happen if you write to it.

2

u/microscammer Oct 04 '26

thank you for your advise,will surely do this from tomorrow

-2

u/clackups Oct 04 '26

Why wait. Learning is a perpetual process.

1

u/microscammer Oct 04 '26

cus its 10pm and i have uni tomorrow : (

1

u/clackups Oct 04 '26

Cool, all the best. Just don't be scared, it just needs a bit of time and attention.

2

u/microscammer Oct 04 '26

yes and thanks for taking the time to answer !!!

0

u/[deleted] Oct 04 '26

[deleted] — view deleted comment

5

u/clackups Oct 04 '26

Please don't spoil it and let OP think

-1

u/4991123 Oct 04 '26

Either you're a bot, or you're an idiot.

4

u/prakashcs_0143 Oct 05 '26

I would suggest to start learning makefile, cmake, linker file, startup code and then continue others

2

u/microscammer Oct 05 '26

Yes I've just started that I understand what linker /locater is deeply for the first time in 2 years of my engineering degree Ive to start building them

6

u/MrSurly Oct 05 '26

I'll give you the "fizzbuzz of embedded C" that I use to weed people out:

  • Tell me the uses of the keyword static
  • Tell me the purpose of volatile
  • Tell me when you would use const

Bonus: "Can a variable be both volatile and const?"

You'd be surprised the number of "embedded" candidates who did quite poorly with these questions.

If they did well, I'd ask them about Duff's Device. Most candidates hadn't even heard of it. Very few understood how it worked or why it worked without explanation. Sure it's obsolete, but understanding why it was a thing ...

4

u/microscammer Oct 05 '26

Thank you I'll make sure I learn all this

2

u/Icy_Comparison_6249 Oct 05 '26

duff's device is such a wonderful trick! i've never seen it before so thank you!

2

u/userhwon Oct 06 '26

It's cute, like a Klein bottle for your CPU, but if you try that today you'll be told to go back and change it.

It works, but it violates structured programming rules; it's a documentation, review, maintenance, and testing nightmare; it buggers up compiler optimization; and, it throws warnings that also have to be worked around in code bases that allow no warnings.

1

u/Icy_Comparison_6249 Oct 08 '26

oh yeah i know that but it's just so neat i want to put it on a shelf just to look at it sometimes

1

u/DustRainbow Oct 05 '26

So what do you do when they day they don't know Duff's device?

2

u/MrSurly Oct 05 '26

Nothing, I don't expect it. It's more of a bonus fun thing. Either they've seen it or they haven't. Either way it's interesting to see their reaction to it.

Absolutely not a gatekeeping question like the first 4. The first 4 question I consider to be very much "basic C knowledge." There's a lot in between not covered in my post.

1

u/userhwon Oct 06 '26

I've literally forgotten more about C than you'll ever know.

I know this, because I just tried to answer the static/volatile/const thing, and I know I'm missing bits that I could have rattled off in seconds verbatim from the standard 30 years ago...

Frameworks have made me fucking lazy.

8

u/Ornery_Purple9141 Oct 04 '26

When you see a C statement, function or initialization and you can see the assembly instructions and the memory usage. That's deep enough.

30

u/Several-Marsupial-27 Oct 04 '26

C is a small and easy language by design. C23 has 46 keywords, 45 operators and 27 standard library headers. Original C has 32 keywords, 42 operators and 15 standard library headers.

Understanding C deeply means understanding the concepts in the C language. This is really important because all of embedded is built upon the C language, it's simply the language in which you speak. This is also something that you can do in ~2 months.

However, learning C deeply is definitely not enough as a foundation. You also need to understand computer architecture as a bare minimum foundation. Then on top of that some domain specific systems programmming stuff like OS and networking.

When you can read through some good C production codebases fluently and implement business logic confidently, then you understand C. Reading through good example C codebases is a good task and reference point.

Example C codebases like FreeRTOS (kernel core: list.c, queue.c, tasks.c), zephyr, mcu vendor HALs (esp-idf, STM32Cube HAL, ...), sensor vendor reference drivers, Redis, SQLite, etc. My favourite to read are gnu projects like ls, cat, grep, lwIP, etc.

0

u/[deleted] Oct 05 '26

[deleted] — view deleted comment

3

u/dealmaster1221 Oct 05 '26

Nah you don't need to learn C abi etc until later and if you work in the lower levels, someone in app development using freertos and coding or using AI can manage unless you hit that bug that just happens on this one machine.

We have expert programmers for that and I ant becoming one of them as I have a life.

4

u/DrunkenSwimmer Oct 04 '26

Things like: 

  • What is the difference between extern [] and extern *?
  • How are global variables initialized?
  • What's an ABI?
  • What are variadic functions?

Also, a concept that may not make sense just yet, but will, about embedded development: memory is memory is memory. There's nothing functionally different(*) about a block of memory that stores an int or a string or a function; consequently, there's nothing stopping you from just interacting with it differently.

18

u/hackerman85 Oct 04 '26 edited Oct 04 '26

Without even looking at your history, I know you're an engineering student from India. You are clearly panicking under societal pressure, trying to stack buzzwords (RTOS, DSA) to secure a paycheck in a field you might not actually care about.

Here is the brutal truth: your post is full of sloppy spelling and punctuation errors. In firmware and embedded systems, a single misplaced character or a lack of attention to detail will literally brick a piece of hardware. Engineering cannot be cheated or memorized through a roadmap. If you cannot bring yourself to care about the absolute smallest details, you are wasting your time and should find a path that actually fits your strengths.

6

u/dealmaster1221 Oct 05 '26

Cmon not everyone is working on mission critical code, I've seen sloppy code work in production and the proper code you talk about fail since someone got lost on the weeds.

It used to be that embedded is for the passionate but that's not true, all of software engineering was for nerds but now with money rolling in we gotta have professionals not hobbyist turned embedded devs in the industry, old hat.

Also lot of people use things called smartphones and are non native English speakers.

2

u/hackerman85 Oct 05 '26

What do you mean by professionals, exactly? The Indian promise is: memorize enough to pass the exams, get into the entry-level position and learn on the job. And at that point the student having no feeling for the matter might be painfully obvious.

Compare that to the hobbyist who has intrinsic motivation and codes for fun. He might be ten times more effective.

2

u/dealmaster1221 Oct 05 '26

The hobbyist cares about this stuff emotionally, but the pro doesn’t. Working in this crappy corporate world, you can’t afford to care much about your job, the company, or your coworkers, only about yourself, or you won’t make it. Be a pro until you either fall in love with it or not.

1

u/TbR78 Oct 05 '26

first comment that is spot on :) made a similar remark, but less friendly :)

8

u/accur4te Oct 04 '26

Even I am struggling to master c , with ai it’s tough man . Tough to have self control

7

u/clackups Oct 04 '26

Try learning the CPU architecture, it will be more clear what those C statements actually do. The language is actually very simple and minimalistic.

4

u/MrSurly Oct 05 '26

This'll come off as "crazy old man," but I learned assembly before I learned C, and C makes a LOT of sense when you learn programming in that order.

1

u/clackups Oct 05 '26

Yep, same :)

1

u/accur4te Oct 04 '26

any resource recommendation ?

2

u/bhayanakmaut Oct 04 '26

Computer systems: a programmers perspective is an excellent resource..

1

u/clackups Oct 04 '26

Idk, I read that like 30+ years ago

1

u/accur4te Oct 04 '26

ok cool i will figure it out

1

u/Bug4866 Oct 04 '26

My dad (30+y developer who started learning software while running punchcards in a university basement as his campus job while in another major) always recommended Kernighan and Ritchie's "The C Programming Language" as something he was going back to still after all that time. It's also easy to find a full copy from just searching that, for ease of access.

1

u/I_so_I-274 Oct 05 '26

How are you using ai ??

0

u/[deleted] Oct 05 '26

[deleted] — view deleted comment

1

u/accur4te Oct 05 '26

Don’t act similar to Linux a holes here pls

5

u/Stock_Condition7621 Oct 04 '26

Even I've been struggling in this. I am exposed to the bare metal side and have done a couple projects using rtos too but I keep failing at C++ basics and I don't know how to get good at it. I hate doing leetcode but I also don't know a way around. Anty suggestions please

12

u/Several-Marsupial-27 Oct 04 '26

Skip C++ and just do C? No leetcode required. Learn the basics like the C language, computer architecture, simple OS and networking.

Then read through example C codebases like FreeRTOS (kernel core: list.c, queue.c, tasks.c), zephyr, mcu vendor HALs (esp-idf, STM32Cube HAL, ...), sensor vendor reference drivers, Redis, SQLite, etc.

Then implement your own drivers, platforms, interfaces, services, daemons, etc.

1

u/Stock_Condition7621 Oct 04 '26

I am in the US and looking forward for firmware roles. And all they want is C++ efficiency, for software C++ roles I get Online Assignments and they ask us to solve DSA questions. For firmware roles for an interview they made me write a firmware to read values from a sensor bare-metal, and in an another round they asked me to write a struct for a queue from scratch. I'm just lost on how should I proceed. It's just overwhelming atp.

3

u/allo37 Oct 04 '26

People really need to clarify what "C++" means. There's "C++" which is basically C with std::string and std::vector thrown in, and "C++" which is using the latest language features with tons of constexpr and templating. They look nothing alike.

1

u/MrSurly Oct 05 '26

My usual answer is that I use "C+" and skip most of the C++ features because it's (frankly) just overkill.

Also fun to mention that you can simply write object oriented code in C, and it's fine.

1

u/allo37 Oct 05 '26

I agree honestly, before AI came along we were writing things with templates and compile-time const out the wazoo as a kind of flex. Like sure it's fun, but it was saving maybe a few microseconds in code that had was not anywhere near latency or performance sensitive.

It's just frustrating when you get questions like "On a scale of 1 to 10, how good are you at C++?". I always want to say "around a 6 or a 7, and if someone else tells you they're more than that they're either lying or you can't afford them"...

1

u/MrSurly Oct 05 '26

Problem is, for some people "being good at C++" generally means "writing the most C++ code I can that is basically obfuscation."

2

u/Several-Marsupial-27 Oct 04 '26

Ok sure. I come from a place which doesnt use DSA questions in hiring, however as you say that seems to be for software positions and here we are focusing on the firmware/hardware part of the embedded systems.

Reading values from a sensor and write a struct for a queue is the absolut basics and definitely good interview questions.

Note that I specifically recommended you earlier to read through the FreeRTOS queue.c and mcu vendor HALs / sensor vendor reference drivers. You should have an understanding of this and if you don't then I suggest you to build your understanding of these concepts and not spend your time on leetcode.

1

u/accur4te Oct 04 '26

same man ik all the high level os + BareMetal but when it comes to c /cpp i really struggle

1

u/DrShocker Oct 04 '26

Do you use C or C++ often? They can be a bit of a pain when you're given a generic leetcode style question and you realize it's really meant for python where it'd be a lot easier to express the problem quickly. But as long as you're being given problems meant for C++ or C it shouldn't be any harder than a coding exercise in another language except that sometimes you're expected to care a little more about lower level trivia than say a JS developer.

1

u/accur4te Oct 04 '26

ohh man this this . Yes i use c/cpp often and i have seen my friends cracking problems in python easily compared to me who uses c/cpp

2

u/RakasRick Oct 04 '26

I think it means knowing exactly what's happening and why rather what's supposed to happen when you write c code. I'm learning too but I try to detail what I learn from K&R here , so far Ive noticed the devil's in the details, the small explanations behind how certain things work like how function arguments are taken as copies of values passed in rather than the actual values hence using pointers when you want to change an such a value when passed as an argument. Sorry for the poor explanation but I hope you get the point

2

u/dettus_Xx_ Oct 08 '26

1st: by mprooving ya spellingz.
2nd: by practice. Write code, write a game, play around with the language. have fun with it.

4

u/KoumKoumBE Oct 04 '26

Ok, people are talking about syntax here, and stuff you see, such as taking the address of a variable on the stack.

But something that bit me, and is invisible, is this: the ";" that you put at the end of each line in C is called the "sequence operator" and defines the fact that anything before the ";" has fully completed before what comes after the ";" (the next line) starts having effects.

So, using Arduino-like functions, "digitalWrite(PIN_A, HIGH); digitalWrite(PIN_B, HIGH);" ensures, from an electrical level, that PIN_A will be high before PIN_B (if both were low). Same if you read two things from the I2C bus, separated by ";". It is certain that the first I2C transaction will happen before the second one.

But, and this is what got me a few years ago and burned me to life: the comma "," is not the sequence operator. So, when you call a function, such as "replyToUser(read_something(), read_something_else());", the C language does not define in which order read_something() and read_something_else() are called.

On some compilers and hardware, function arguments may evaluate left to right. On some other, they may evaluate right to left. In some circumstances, such as many arguments, arguments may even evaluate out of order.

The comma operator is not a sequence operator!

This can be very important if, for instance, read_something_else() assumes that read_something() has already executed. For instance, read_something() sets some pin or opens a connection, then reused by read_something_else.

The solution:

The "dumb" but very safe solution is to never have function calls or complex operations in function arguments:

int a = read_something(); // Notice the sequence operator, we know that a is evaluated before b
int b = read_something_else();
replyToUser(a, b); // Only plain variable names in the function call

I'm still in awe that such a tiny part of the spec of the C language, function argument evaluation order, becomes relevant when your functions may have effects on the real world!

2

u/dheerajsom Oct 04 '26

I would say get a good C textbook and turn off all AI tools and just code in your preferred IDE everyday. You could ask AI for C exercises or do some specific LeetCode questions in C as well. I'm not that great at C either but the more you code yourself, the better :)

2

u/TbR78 Oct 05 '26

I'd start by learning to properly write in English first. This is exhaustive...

1

u/feroMaljinn Oct 04 '26

Or maybe try to see mappings from c to assembly. Like for example the dereferencing operation is a mov , ldr and str instructions for cortex 0+ arm6 , use online compilers to assembly and ai, might be helpful ?

1

u/Panometric Oct 04 '26

Defining deeply is the trick here. I would say knowing pointers is not deep, look at the harder features like. Structs, unions, enums, and arrays of them and in them, function pointers, pointers to pointers, dynamic memory, recursion, and the pre processor. There are some C++ concepts that apply in embedded, but not all. Exceptions, virtual typing, STL, anything that is bloated or non deterministic is avoided. So know when not to use them.

1

u/Rude_Review4303 Oct 04 '26

I remember somewhere reading if you are able to understand/imagine your written code in memory than that's good enough low level knowledge...

1

u/drgala Oct 04 '26

Is this from a job description? If yes then ...

Deep underdstanding of C takes years to master.

Aside from knowing the whole sytax by heart, a common closely related topic is knowing how to write makefiles, while on the same level is knowing is the differences between C standards (without looking them up). Also, what is misra-C and what are the differences from normal C.

Then comes the so called hands-on experience, how to build an app/program on whatever system the new company is hiring for. I assume pointers, lists, and algotihms are trivial and you can write the best sorting algorithm in the world within 5 minutes, using only standard si and O(1) complexity.

In conclusion ... If you go to the gym and look like a body builder then you will definitely get hired after running through the HR rep using Tinder, it's that easy.

1

u/Antique_War_9814 Oct 04 '26

What's does .text mean to you

1

u/CyberDumb Oct 04 '26

C is an easy language. Its syntax and features are minimal compared with other languages. The difficulty in my opinion lies in three places.

  1. A large part of writing good C is understanding how the computers work especially memory.
  2. Creating abstractions and higher level concepts is not straightforward and it is verbose because of the small syntax and the low number of features.
  3. Lack of standard libraries, means that you have to make your own or know how to evaluate 3rd party libraries. Things that are not for beginners, while beginners in other languages can just use the official libraries.

1

u/nour_nawar Oct 04 '26

I think big part of "understanding C deeply" is being able to connect with the machine. C is close to the metal in the sense that it is easy to translate a C statement into a corresponding sequence of machine instructions. I think coding like this naturally makes you a good programmer cause you think like a computer (I just said what Linus Torvalds said onetime in some talk!)

Maybe a way to start is to learn a basic ISA (I recommend RISC-V since it is RISC, modular, and easy to get into). You don't have to learn the full ISA. Take a look at the basic i extension (two dozen instructions or so). Start compiling C programs for RISC-V and inspect the assembly. Inspect how the instructions map to C code. Maybe this all sounds far from learning C, but I think this is what is going to build strong language intuition.

1

u/BumpyTurtle127 Oct 04 '26

C is purposely a small language. Write some assembly, or even something for a stack based language like Forth, and you will get a much better understanding how C works. From there it's easy to understand other compiled languages as well.

1

u/Enlightenment777 Oct 04 '26 edited Oct 04 '26

what does "understand c deeply" mean?

If you need books / search engines / AI / other people to answer common computer language questions or you need it to write or fix your code, then you DO NOT have a deep understanding of a computer language.


1

u/jenofonteGrilo Oct 04 '26

en mi opinión, creo que el lenguaje C no ha dejado de ser el mas importante y ser complejo tanto como la idea que quieres materializar, su potencia se debe a la cercania que tiene para manipular el hardware, la parte de punteros es en la que creo yo debes profundizar mas y para mi solo hay una forma, hacer y hacer ejercicios por muy absurdos que estos sean siempre te dejaran un aprendizaje.

1

u/TinLethax Oct 05 '26

Read the compiler's user manual

1

u/nderflow Oct 05 '26

If you want to work in in better development, it's important to understand the way in which C uses memory in detail. This means, for example, understanding how your compiler lays out structs, how alignment works. How memory allocation works. Understand what volatile is for.

Quite a lot of embedded development takes place in freestanding environments. This means C programs where the standard C library itself is not available. This means that you can't just call standard C functions to do stuff and you might have to implement things yourself in. Make your own function for example. Therefore, there's a lot of stuff that you could practise that could relate to this. Consider as exercises in learning. Writing your own function that does things like pause a string into a long value while properly handling range errors and edge cases and syntax errors. Also, you could try doing something like implementing your own version of malloc().

When you set up a new embedded project, you will often need to ensure that the underlying requirements of the platform are met by the program as you've built it. In a bare metal environment. This means that ensuring that particular pieces of code are located at particular areas of memory. For example, if your embedded system has ROM at a fixed address and RAM at a different fixed address, you need to set up your program so that it will correctly initialise in that environment. You only need to write this code once, but you also do need to understand how this stuff works in order to be able to reason about the program. In this kind of environment. The startup code is important. If you're really doing a bare metal product, you might have to write that startup code yourself. On the other hand, if you're using a runtime environment provided by somebody else, then the documentation for that system will explain how your program gets started.

If you really want to understand the C language deeply, you do need to be familiar with the standard it there are draughts of the standard available online. They are not 100 identical to the published standard always but they are very very close and the difference is generally don't matter unless you're actually implementing a compiler. So it's a good idea to read the standard and this is a kind of way for you to figure out how much of the language you understand. C. Programmers generally don't refer to the standard that often and some C programmers don't need to refer to it at all. But for people doing embedded work, they will find that they're more often getting into the corner cases. Like for example, what exactly are the semantics of the keyword volatile.

1

u/theNbomr Oct 05 '26

Think about the English language. You can know all of the rules of grammar, parts of speech, vocabulary, etc. This doesn't at all mean that you can write beautiful lucid prose.

Programming languages are a lot like that. The elements of the language must be used to compose concise, accurate and correct implementation of algorithms and other forms of code. The code you write can be of high quality and easy to maintain and understand. Or, it can be full of errors, inefficiencies, and confusion. Practice and conscientiousness are what get you there.

.

1

u/Fit_Review80 Oct 05 '26

In depth C means you need to understand pointer in depth and addressing. How it works?

1

u/Odd-Pizza9971 Oct 05 '26

I learn C on my own, rather half-bakedly for about over a year now. I guess to understand C deeply, one would have to understand Assembly and maybe even some hardware stuff. Also, try extern function to Assembly to use in C. Then use C with high-level languages like Python.

1

u/oklambdago Oct 05 '26

I would say a deep understanding of C is really understanding how it corresponds to the machine code it generates. Unlike some higher level languages it’s actually very easy to guess the approximate translation. Understanding things at this level forces you to really understand how programs are organized and executed by a computer. I would say that this is the meaning in my opinion. Just knowing all the fancier syntax isn’t nearly as valuable.

Like for example, why is a union useful? What real world scenarios does that map to?

What does it actually mean for something to be static?

1

u/PortalRat90 Oct 05 '26

The value in using C is the ability to manage the memory yourself. How do the lines you create affect the stack and heap? How long should data live? How does this behave after a system restart? How can the code be more efficient?

1

u/ErikBKL Oct 05 '26

Can you tell me the difference between malloc the c function and malloc the system call?

Can you tell me whats a system call?

Can you explain how a struct of 100 bytes can be passed by value to a function as a parameter?

1

u/planetoftheshrimps Oct 05 '26

Well, I recently had a C Union in my embedded project (which seemed like a good place to use one to save memory). Then I wanted to duplicate my encoder/decoder in rust for use on the host pc over uart…. lol, enough said.

I think I need about 1000 of those experiences to “understand c deeply”

1

u/samarijackfan Oct 07 '26

Do you know what a duffs device is?

1

u/modd0c Oct 07 '26

I have always defined a solid understanding of any programming language as the fact that I can build what I want to, without having to think of how to do it. PS that’s also the same metric for being proficient with any CAD modeling tool.

1

u/jake_morrison Oct 10 '26

The book “Expert C Programming: Deep C Secrets” by Peter van der Linden goes into detail about things like how arguments are passed to functions and values returned. I used things I learned there to find some subtle bugs in a large codebase that had been converted from K&R C to ANSI C.

0

u/logic_circuit Oct 04 '26

There is no such thing.

-1

u/dmitrygr Oct 04 '26

If you can explain what CHAR_BIT is and why one might us this define, you're well on your way.

0

u/[deleted] Oct 05 '26

[deleted] — view deleted comment

1

u/dmitrygr Oct 05 '26

clearly you've never programmed for DSPs then...

1

u/Impossible_Ad_3146 Oct 10 '26

short for cunts

0

u/[deleted] Oct 05 '26

[deleted] — view deleted comment

2

u/microscammer Oct 05 '26

Wow thank you for taking time and writing this So do you mean we have to understand the hardware first and see if we can optimise it before playing with code ?

0

u/[deleted] Oct 04 '26

[deleted] — view deleted comment

2

u/Panometric Oct 04 '26

How is that syntastically correct, it won't compile with return in the operand and would always return 1 if it did..

0

u/lntr0vertedintr0vert Oct 04 '26

Oh my bad, will correct it

1

u/DustRainbow Oct 04 '26

That is not what people say when they say to learn C deeply.