S
Spoon
Hello,
Is the following code valid:
char buf[1024];
int size = 666;
size += sprintf(buf+size, "%d", size);
size += sprintf(buf+size, "%d", size);
(Expected behavior: at offset 666, buf contains "666669\0".)
Is it equivalent to the following code:
char buf[1024];
int size = 666;
int temp = sprintf(buf+size, "%d", size);
size += temp;
int temp = sprintf(buf+size, "%d", size);
size += temp;
AFAIU, the function call is a sequence point, therefore size can only be
updated after sprintf has been evaluated with the "old" value of size.
This reasoning might be incorrect if sprintf were a macro, right?
(Can it be?)
Regards.
Is the following code valid:
char buf[1024];
int size = 666;
size += sprintf(buf+size, "%d", size);
size += sprintf(buf+size, "%d", size);
(Expected behavior: at offset 666, buf contains "666669\0".)
Is it equivalent to the following code:
char buf[1024];
int size = 666;
int temp = sprintf(buf+size, "%d", size);
size += temp;
int temp = sprintf(buf+size, "%d", size);
size += temp;
AFAIU, the function call is a sequence point, therefore size can only be
updated after sprintf has been evaluated with the "old" value of size.
This reasoning might be incorrect if sprintf were a macro, right?
(Can it be?)
Regards.