Re: [PIC] Learning C

CDB <[email protected]>
Newsgroups gmane.comp.hardware.microcontrollers.pic
Message-ID <[email protected]>
I have always separated the difference of =  and == in C by referring to 
the latter as 'is the same as'

if (X is the same as Y) then ......  if (X == Y) then
x = y       x now contains the value of Y.

Colin


--

[email protected]  11 November 2024

Hosted by:  www.superdomains.com.au

This email is to be considered private if addressed to a named  
individual or Personnel Department, and public if addressed to a blog,  
forum or news article.



__________________________________
Sent from eM Client | www.emclient.com <https://www.emclient.com/get>


On 11/11/2024 08:24:15, "smplx" <[email protected]> wrote:

>
>
>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
>
>-- http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
>View/change your membership options at
>https://mailman.mit.edu/mailman/listinfo/piclist
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.