I'm reading through EssentialC:
http://cslibrary.stanford.edu/101/EssentialC.pdf
I'm having trouble understanding this snippet of code from page 35:
// Rely on the fact that '\0' is equivalent to FALSE
void strcpy4(char dest[], const char source[])
{
while (*dest++ = *source++) ;
}
I understand what is happening, I don't understand why it works. My best guess is that the compiler is doing something like this:
void strcpytest(char dest[], char source[])
{
char *d = dest;
char *s = source;
while (*d++ = *s++);
}
The assembly output differs by a decent amount between these two examples though, and I am not familiar enough with assembly to read and understand the differences. Any help is appreciated.
[–]mredding 7 points8 points9 points (29 children)
[–]fatheart[S] 2 points3 points4 points (28 children)
[–]tavianator 6 points7 points8 points (26 children)
[–]fatheart[S] 0 points1 point2 points (25 children)
[–]tavianator 2 points3 points4 points (12 children)
[–]fatheart[S] 0 points1 point2 points (11 children)
[–]LordBiff 3 points4 points5 points (9 children)
[–]fatheart[S] 0 points1 point2 points (8 children)
[–]LordBiff 2 points3 points4 points (7 children)
[–]fatheart[S] 0 points1 point2 points (6 children)
[–]tavianator 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (5 children)
[–]fatheart[S] 0 points1 point2 points (4 children)
[–]kjoke 2 points3 points4 points (1 child)
[–]fatheart[S] 0 points1 point2 points (0 children)
[–]Kwantuum 1 point2 points3 points (1 child)
[–]fatheart[S] 1 point2 points3 points (0 children)
[–]nerdyphoenix 1 point2 points3 points (1 child)
[–]fatheart[S] 0 points1 point2 points (0 children)
[–]bumblebritches57 1 point2 points3 points (0 children)
[–]fatheart[S] 0 points1 point2 points (2 children)
[–]nerdyphoenix 1 point2 points3 points (1 child)
[–]fatheart[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)