7

Up until recently, have been trying to validate user input by writing lengthy if-statetments nested in while-loops. I usually have the while-loop check that the function that takes input - for instance getchar() - is not EOF and the if-statement checking whether input is of the desired data type and/or size. But then I noticed people doing something similar with infinite loops while(1) and for(;;).

While I understand that these loops are infinite because there is no condition to check against in for(;;) and because the condition is always true in while(1), I wonder if there is a more pedagogical (?) way of expressing the same thing. Like a proof of concept, or like what's going on at the electronic/logic level, if one were to draw this on a schematic with logic gates.

Or am I perhaps overthinking it and there is "simply" a signal/transistor somewhere that is always on/1/true/has the approproate votlage? Feels like "fooling" the machine by writing while(1) or for (;;) ....

you are viewing a single comment's thread
view the rest of the comments
[-] owenfromcanada@lemmy.ca 2 points 1 day ago

Assemblers can come from the CPU manufacturer, but they can also come from a third party. They're most often bundled into the compiler, since it's rare to need to compile without also assembling (many compilers skip the assembly step and convert directly to machine code). There's actually a third tool involved I didn't mention, which is a Linker (takes pieces of machine code and combines them together, so you can separate your software into different parts).

Some CPUs are more niche, and the assemblers/compilers for them sometimes are created by the manufacturer. But there are a few "standard" processor architectures that many CPUs follow, and because they're common between many brands of CPU (and the architectures are published and well known), the compilers are often created by third parties. And there are some compilers (like gcc) that can compile to dozens of different architectures.

As an example, you might have heard terms like x86, x86_64, armv7, or RISC-V -- these are all processor "architectures", which means that any processor that meets a particular architecture can run machine code built for that architecture. Currently, x86/64 architectures are common among desktops and most laptops (Intel and AMD processors), while ARM architectures are common for tablets and phones and some laptops (Snapdragon processors, for example).

this post was submitted on 26 May 2026
7 points (100.0% liked)

C Programming Language

1302 readers
2 users here now

Welcome to the C community!

C is quirky, flawed, and an enormous success.
... When I read commentary about suggestions for where C should go, I often think back and give thanks that it wasn't developed under the advice of a worldwide crowd.
... The only way to learn a new programming language is by writing programs in it.

© Dennis Ritchie

🌐 https://en.cppreference.com/w/c

founded 2 years ago
MODERATORS