5 ms·
Good point. I'm not sure why all snippets have *to = *from++; while it should be *to++ = *from++;
by merraksh 10y ago
Good point. I'm not sure why all snippets have
*to = *from++;
while it should be
*to++ = *from++;
- pdpi 10y agoActually, the examples are correct. The context for this particular snippet is memory-mapped IO, so the `to` pointer is actually the memory address where some external device is mapped to and accepting input. Repeatedly writing to that location causes the values to be sent to the device.
- merraksh 10y agoOK, thanks for the explanation.
- cytzol 10y agoThis is a perfect example of why comments that explain why something is going on, rather than just what is going on, are so useful!
- aninhumer 10y agoI think in this case you could just put the write into a function/macro that documents it's intent.
- to3m 10y agoIt already is - the function is called "send", and rather than wasting its time just doing one write, it does a whole pile of them at once ;)
- mannykannot 10y agoThere are many good reasons for making functions, and occasionally even a good reason to write a macro, but avoiding writing a comment is not one of them.
- aninhumer 10y agoI disagree. Writing a comment to express something that can adequately be expressed by code adds overhead to reading it.
- mannykannot 10y agoThat looks to me like a made-up problem. I could be persuaded otherwise, though, so post some code that shows how it works for this particular case.
- deleted 10y ago[deleted]