Re: [PATCH 00/11] pragma once: treewide conversion

From: Luc Van Oostenryck
Date: Sun Feb 28 2021 - 19:37:01 EST


On Sun, Feb 28, 2021 at 10:34:46PM +0300, Alexey Dobriyan wrote:
>
> gcc does
>
> open "/" + "whatever between quotes"
> fstat
>
> so that "1.h" and "./1.h" differ

When I try the following with GCC 10.2:
$ cat header.h
#pragma once
#include "./header.h"
.. plenty of stuff ..

$ strace -f gcc -E header.h

I see that the file is opened 4 times (3 times with the name "header.h"
and once with "./header.h"). Each of these open is followed by a fstat().
More annoyingly, the file is also read 4 times (3 times entirely and once
only the fist 4096 bytes).

When the equivalent is done with an include guard instead, the file is
only read twice (once with each names) and read twice (entirely).

-- Luc