3 ms·
> I can't imagine any way in which volatile would cause problems. What are you pondering? Termination condition. Which data applies and does it have to be rer
by bsder 13y ago
> I can't imagine any way in which volatile would cause problems. What are you pondering?
Termination condition. Which data applies and does it have to be reread after the assignment?
- userbinator 13y agoIt is read once and written once, and the value that was read is the value of the expression. Note that this "elaborated" version, while(*src) { char c = *src; src++; *dst = c; dst++; } if the pointers were volatile, would actually read the source value twice.
- bsder 13y agoThe original while loop is functioning more like a do {} while() loop and the c is declared outside. char c; do { c = *src; src++; *dst = c; dst++; } while (c != '\0'); But, even here, people reading the code can reason about the volatiles without having to go look up the standard. And don't even get me started about compiler implementation of volatile.
- Dylan16807 13y agoSo your conclusion is that the original code is more logical with regard to volatile pointers, even though calling it with one would mean casting away the volatile and basically inviting disaster? No coding style is immune to problems caused by changing the number of reads to a variable. Volatile is an exceptional thing that must be treated with care and heavy documentation. It has no relevance to the quality of a normal-code strcpy.