What is the purpose of the restriction in tmpfile_s?

From project C11:

C11 (n1570), ยง K.3.5.1.1 Function tmpfile_s
errno_t tmpfile_s(FILE * restrict * restrict streamptr);

What is the purpose of qualifying restrict here?

Since there are no other parameters, the compiler may know that streamptr not smoothed without restrict , is it?

+7
source share
1 answer

There are several global variables that are of type FILE* , for example stdout and stderr . Therefore, the leftmost restrict clearly indicates that none of them can be returned, the returned FILE* not an alias with any other. The second restrict makes the same guarantee, but one level higher, you are not allowed to skip something like &stderr in this function. (Well stderr not necessarily a variable in the usual sense, but I hope you see the picture.)

+5
source

All Articles