Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Strict aliasing and restrict |
| Date | 2015-11-21 12:41 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <87poz3o789.fsf@bsb.me.uk> (permalink) |
| References | <n2pn3q$qv0$1@news.albasani.net> |
Johannes Bauer <dfnsonfsduifb@gmx.de> writes: > Hi group, > > I've got a question about strict aliasing and the restrict keyword. > > Why is "restrict" needed in the first place? It is my understanding that > strict aliasing is something that any conforming compiler might assume > at any point in time anyways. That would, however, contradict "restrict" > -- because if strict aliasing was allowed everywhere, there would not be > a need to explicitly declare it for some cases. Strict aliasing is an invented term that does not appear in the standard. I sense that it is often used like "politically correct" -- it's never intended to be a good thing, just a label for aliasing that the author objects to. (I'm not saying you are doing that, just pointing out that it's a term best avoided). > So it appears to me that the strict aliasing rule does not apply > everywhere and "restrict" gives the programmer the ability to specify > explicitly that it should, however, apply here and there. void f(int *p1, int *p2); The effective type rules allow a compiler to assume that lvalue expressions with different types refer to distinct objects, but that's not possible in the case above. To tell the compiler that p1 and p2 don't alias you need restrict. I think, also, that the rules about restrict-qualified pointers are stronger than the effective type rules, but I'd need to research that to be sure. Also, restrict allows you to declare non-aliasing in other cases that are allowed by the effective type rules. An lvalue expression of type char, for example, can access any object, so without restrict char pointers could alias almost anything. <snip> -- Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Strict aliasing and restrict Johannes Bauer <dfnsonfsduifb@gmx.de> - 2015-11-21 13:12 +0100
Re: Strict aliasing and restrict James Kuyper <jameskuyper@verizon.net> - 2015-11-21 07:39 -0500
Re: Strict aliasing and restrict supercat@casperkitty.com - 2015-11-21 09:59 -0800
Re: Strict aliasing and restrict Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-21 12:41 +0000
Re: Strict aliasing and restrict Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-11-21 12:52 +0000
Re: Strict aliasing and restrict supercat@casperkitty.com - 2015-11-21 09:14 -0800
Re: Strict aliasing and restrict Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-11-21 19:41 +0000
Re: Strict aliasing and restrict Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-21 14:57 -0500
Re: Strict aliasing and restrict Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-11-22 11:02 +0000
Re: Strict aliasing and restrict supercat@casperkitty.com - 2015-11-21 17:50 -0800
Re: Strict aliasing and restrict Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-11-22 11:18 +0000
Re: Strict aliasing and restrict supercat@casperkitty.com - 2015-11-22 07:45 -0800
Re: Strict aliasing and restrict Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-22 03:41 -0800
Re: Strict aliasing and restrict supercat@casperkitty.com - 2015-11-22 08:02 -0800
Re: Strict aliasing and restrict Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-22 14:39 -0800
Re: Strict aliasing and restrict Ian Collins <ian-news@hotmail.com> - 2015-11-23 11:59 +1300
Re: Strict aliasing and restrict supercat@casperkitty.com - 2015-11-22 15:22 -0800
Re: Strict aliasing and restrict Stephen Sprunk <stephen@sprunk.org> - 2015-11-22 19:22 -0600
Re: Strict aliasing and restrict raltbos@xs4all.nl (Richard Bos) - 2015-11-23 14:07 +0000
Re: Strict aliasing and restrict Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-21 08:17 -0500
Re: Strict aliasing and restrict supercat@casperkitty.com - 2015-11-21 09:45 -0800
Re: Strict aliasing and restrict Stephen Sprunk <stephen@sprunk.org> - 2015-11-22 16:30 -0600
Re: Strict aliasing and restrict supercat@casperkitty.com - 2015-11-22 15:18 -0800
Re: Strict aliasing and restrict Stephen Sprunk <stephen@sprunk.org> - 2015-11-21 16:39 -0600
csiph-web