The signatures for read / write are below:
ssize_t write(int fd, const void *buf, size_t count);
ssize_t read(int fd, void *buf, size_t count);
Why doesn't read()
also take a const void *
? Does that mean it changes the value of buf
?
The signatures for read / write are below:
ssize_t write(int fd, const void *buf, size_t count);
ssize_t read(int fd, void *buf, size_t count);
Why doesn't read()
also take a const void *
? Does that mean it changes the value of buf
?
Because write()
won't change the contents of the buffer, but only write it to the file.
On the other hand, read()
will change its buffer (from what's in the file) so it had better not be const
.
General rule, what changes isn't const
.