3 ms·
The 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;
by bsder 13y ago
The 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.