1
\$\begingroup\$

Someone I know wants to learn C, but run their own programs and exercises on a PC. Which is all well and good until we get to pointers. Is there a significant chance of them damaging the PC or crashing it?

\$\endgroup\$
7
  • 2
    \$\begingroup\$ This question may not be suitable for EE.SE. Having said that, the chance is nearly zero with modern PCs. As long as you don't delete important system files. Use a virtual machine for added safety. You can even delete the system files inside the virtual machine. Just delete the virtual machine later. \$\endgroup\$ – AJN Sep 13 '20 at 11:50
  • \$\begingroup\$ @AJN I posted it here because almost everyone here uses C, or C++. It's the de facto hardware programming language. Plus they will be moving on to a dev board at some point \$\endgroup\$ – Dirk Bruere Sep 13 '20 at 11:55
  • 2
    \$\begingroup\$ Highly unlikely that under an OS an user space application has enough privileges to do damage. But it all depends what kind of application you are programming, for example a program that finds a file and deletes it can have a bug and it will delete all your files. Run your program under a virtual machine or other sandbox where it cannot do any damage if it scares you, but I don't recall anyone making so heavy precautions when learning C. Also, it depends if you use pointers to data, or pointers to functions, so will you read and write bad data, or jump to execute arbitrary code. \$\endgroup\$ – Justme Sep 13 '20 at 13:18
  • 1
    \$\begingroup\$ In DOS or Windows 3.1 maybe. Have them use a newer operating system. \$\endgroup\$ – user_1818839 Sep 13 '20 at 13:55
  • 1
    \$\begingroup\$ I have done a whole lot of Windows PC programming, but the only times I actually damaged the PC was when I meddled around with PCBs connected to it and accidentally got 24VDC on the wrong line. (I accidentally connected my scope ground reference to 24VDC just the other week, the PC monitor went black but survived...) So I think your PC should fear the average EE far more than it should fear a newbie learning programming. \$\endgroup\$ – Lundin Sep 14 '20 at 12:49
3
\$\begingroup\$

Is there a significant chance of them damaging the PC or crashing it?

I'll ignore the "crashing" aspect (no, that's why we have process isolation) for now, and focus on what is on-topic for an EE.SE site:

Damage could only happen if you somehow made the hardware do something that damages it.

You won't be able to do that with a beginner's toolset. Sure, if you work as super user (a beginner wouldn't do that) and access a badly written driver (why would a beginner access a driver directly?) and instruct it to do something harmful (whatever that might be), yeah. There's potential for danger.

Remember, unless you're writing an early stage for your boot process, or a kernel component for your OS, you never access the raw memory of your machine, so accessing memory doesn't have side effects aside from the interfaces to hardware your OS offers you.

That's one of the many reasons one would recommend that people learn programming on a "proper" PC instead of on a microcontroller if they intend to deal with memory: The absence of hardware access makes everything safe, and way easier to debug.

In reality, I've never seen a beginner do beginner things that broke a PC. Like, I've seen people seriously torture keyboards in frustration, but that's not really the point here.

\$\endgroup\$
1
\$\begingroup\$

In a modern PC running a modern OS, there is virtually no chance of actually damaging anything (apart from the keyboard and their ego perhaps).

Errant programs (null dereference or file errors perhaps) will normally be not responding or terminated or perhaps give a segmentation fault.

One place to be careful is with files where some data might get lost or corrupted (and then usually only if you are using fwrite() or fread() with seek) but provided they are not system files (which are normally protected anyway) then it can be a valuable lesson.

File handling is actually a very important thing to learn, incidentally, particularly in C.

As noted by Marcus Muller this is not true when doing code on bare metal with a development kit. I have seen quite a few of those become door stops when the I/O pins are driven when they should not be.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.