2 ms·
It depends on the system. First, the int would be by value anyway, so it wouldn't matter. But assume you handed it a pointer instead. Some are properly marked
by DannyBee 10y ago
It depends on the system. First, the int would be by value anyway, so it wouldn't matter.
But assume you handed it a pointer instead.
Some are properly marked readonly in declarations, some are not[1]
But this is a common problem with unmarked logging. The compiler will infer attributes all the way through things it has bitcode for.
(IE it can determine it to be readonly, readnone, whatever, as long as it can see calls to either functions marked readonly/readnone, or determine the called functions to be readonly/readnone)
But, usually, if you don't give it the whole program, it can't infer that your logging function does not modify its arguments.
[1] Fun fact: glibc allows printf handler registration:
https://www.gnu.org/software/libc/manual/html_node/Customizing-Printf.html https://www.gnu.org/software/libc/manual/html_node/Customizi...
So sadly, it's printf is not readonly, because it can do anything it wants in these callbacks.
(nobody uses the printf registration, though, so it may be time to just add a compiler option required to make it work, and not screw everyone else using printf over)