get_page_size

Bran S archsbran at gmail.com
Sun Jun 14 19:11:13 UTC 2020


Hi,

While reading code I came across this in `tests/get_page_size.c`

size_t
get_page_size(void)
{
    static size_t page_size;

    if (!page_size)
        page_size = sysconf(_SC_PAGESIZE);

    return page_size;
}

Why are we checking for page_size to be zero. Static variables are
always initialized to zero by default right?
Even if they aren't why check for zero, we can just assign the size to
it without doing so, right?
What am I missing here, as I am sure this cannot be a mistake?

Also why not write the above function as:

size_t
get_page_size(void)
{
    return sysconf(_SC_PAGESIZE);
}
Is it because this would be inlined and we don't want that? If so,
then the next question would be why won't we want it to be inlined?
Please clarify whatever it is that I am missing here.


More information about the Strace-devel mailing list