Re: [PIC] Learning C
smplx <[email protected]>
| Newsgroups | gmane.comp.hardware.microcontrollers.pic |
|---|---|
| Message-ID | <[email protected]> |
On Sun, 10 Nov 2024, Neil wrote: > Agree with a couple things from other comments such as C being high-level > assembler and using a PC at first (you can just use gcc already on Linux). > > Already knowing a structured language is very helpful. > But IMO you'll have to wrap your head around pointers, which can get > confusing. I find this C visualizer very helpful for figuring out some > algorithm... https://pythontutor.com/c.html > > One more note: = != == > Or in other words, the equal sign ( = ) and the double equal size ( == ) are > very different things in C. The first assigns a value and the other compares > values. But people new to C will invariably use a single equal for a > comparison and the code is true every time, as C will compile it as valid > code, do the assignment, then the comparison. You have been warned ;P Sorry to wade in here but: if (y = x)... assigns x to y then compares the result to 0. 0 is nomally taken to mean false and "not 0" as true. So it is almost alway true except in the case where x is 0. I'm not sure what happens if x and y are floats and x is a NaN or if x and y are structures. if you're looking for a real headache try debugging a program that contains: if (! x == y)... Trying to learn C on bare metal is like trying to learn to fly by crashing a lot. It's a lot quicker and easier if you learn on a simulator. Friendly Regards Sergio Masci