Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Kaz Kylheku <864-117-4973@kylheku.com> |
|---|---|
| Newsgroups | comp.std.c |
| Subject | What is the point of restrict in fopen? |
| Date | 2023-05-24 23:41 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <20230524162836.172@kylheku.com> (permalink) |
I've noticed that both arguments of fopen are restrict-qualified.
What does this achieve?
If I have:
const char *path = "foobar";
const char *mode = path + 6;
FILE *f = fopen(path, mode);
is the behavior undefined, since the mode pointer accesses
something which is also accessed through path?
What if the code is this:
FILE *f = fopen("foobar", "r");
and the compiler itself merges the two string literals so
that they share storage?
The arguments are treated as immutable by fopen, so what is
the purpose of restrict?
The benefit of restrict is that when an object is being modified through
a restrict-qualified pointer, the implementation is not required to care
whether the object is aliased through another object. Access through the
other pointer can be cached as if that modification didn't happen.
If aliasing is occurring, the behavior is undefined, allowing the
implementor not to care about that situation.
But the arguments to fopen must not be modified.
How can fopen be made faster based on the assurance that the inputs do
not overlap, (and is that really worth breaking programs?)
--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
Back to comp.std.c | Previous | Next — Next in thread | Find similar
What is the point of restrict in fopen? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-05-24 23:41 +0000
Re: What is the point of restrict in fopen? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-07-20 10:17 -0700
Re: What is the point of restrict in fopen? Jakob Bohm <jb-usenet@wisemo.com.invalid> - 2023-07-21 08:55 +0200
Re: What is the point of restrict in fopen? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-07-22 05:37 +0000
Re: What is the point of restrict in fopen? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-07-25 05:35 -0700
Re: What is the point of restrict in fopen? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-07-25 19:33 +0000
Re: What is the point of restrict in fopen? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-08-04 20:15 -0700
Re: What is the point of restrict in fopen? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-07-25 05:37 -0700
csiph-web