Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Stephen Sprunk <stephen@sprunk.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Strict aliasing and restrict |
| Date | 2015-11-22 19:22 -0600 |
| Organization | A noiseless patient Spider |
| Message-ID | <n2tpjp$rua$1@dont-email.me> (permalink) |
| References | (1 earlier) <87poz3o789.fsf@bsb.me.uk> <slrnn50q9b.5q5.grahn+nntp@frailea.sa.invalid> <5831fcba-8de0-4e11-8ef9-8f6229d63935@googlegroups.com> <779099d5-1301-4f43-a2e9-a54f429d84d7@googlegroups.com> <f0b3423a-1782-4321-906a-b325bc7a891f@googlegroups.com> |
On 22-Nov-15 10:02, supercat@casperkitty.com wrote:
> Malcolm McLean wrote:
>> It needs to return the biggest block, so you lose a bit of memory,
>> but you can reuse the block at will, without even calling the
>> allocator again if three machine instructions of overhead is too
>> much for you.
>
> You don't see the real problem. The real problem is that given:
>
> float *fp = _box_alloc(pool); // Allocation function in rtx
> *fp = 12.34;
> _box_free(pool, fp);
> float *ip = _box_alloc(pool); // Allocation function in rtx
> *ip = 5;
> printf("%d", *ip);
> _box_free(pool, ip);
>
> there's no decent way to prevent a compiler from rewriting the code as:
>
> float *fp = _box_alloc(pool); // Allocation function in rtx
> _box_free(pool, fp);
> float *ip = _box_alloc(pool); // Allocation function in rtx
> *ip = 5;
> *fp = 12.34;
> printf("%d", *ip);
> _box_free(pool, ip);
That reordering is not allowed unless the compiler can prove neither ip
nor fp (nor pool?) point to allocated storage. If they do, the behavior
is well-defined. If they don't, the behavior may already be undefined
for other reasons, in which case this is the least of your problems.
S
--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking
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