Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Spurious diagnostic messages |
| Date | 2015-10-12 09:17 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <mvfmlk$v4d$1@dont-email.me> (permalink) |
| References | (20 earlier) <1d376bd3-d7ba-406a-b9cf-9858197cfce3@googlegroups.com> <mv7tgu$eou$1@dont-email.me> <d80db990-b05f-4f2f-8db3-789f108aa0a6@googlegroups.com> <mvdnfo$u9b$1@dont-email.me> <09a8fa9e-5c5d-45a6-943d-96ddb9f05614@googlegroups.com> |
On 11/10/15 23:53, supercat@casperkitty.com wrote:
> On Sunday, October 11, 2015 at 8:18:58 AM UTC-5, David Brown wrote:
>> The compiler (and/or linker) is already free to combine such constant
>> data in certain ways. The C standard requires that different objects
>> (including const objects, even if they are static) have different
>> addresses. But as long as you don't take the address of the constant
>> data, merging is fine (the compiler doesn't even have to make the object
>> in addressable memory if it is not needed).
>
> How often does one have objects of significant size whose address is never
> taken? While some objects might be large enough to be worth storing in
> shareable form and yet not have their address taken, that would seem rather
> rare.
Let me be slightly more accurate here - if the compiler knows that you
are not /comparing/ addresses in any way, then (I think) it is safe to
combine or merge constants.
So if your code has these functions:
char makeHexDigit(unsigned int i) {
static const char digs[] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
if (i > 15) return '?';
return digs[i];
}
char makeDecDigit(unsigned int i) {
static const char digs[] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9'};
if (i > 9) return '?';
return digs[i];
}
Although the program effectively takes the address of these const
objects (for the array look-up), the compiler can safely merge them. (A
quick test with gcc 4.9 fails to merge, even with -fmerge-all-constants.
But in theory, it could!)
>
> Further, even though semantically something like:
>
> CREATE_FNORD(foo, 12, 34, 56);
> ...
> do_something(&foo);
>
> might be semantically equivalent to:
>
> do_something(NEW_FNORD(12,34,56));
>
> I being able to create constants in-line would seem much more convenient
> than having to create them elsewhere. I find it curious that C99 allowed
> for the creation of automatic-lifetime literals, and allows code to take
> their address, but has no handling for static-lifetime constants.
>
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Spurious diagnostic messages Tim Rentsch <txr@alumni.caltech.edu> - 2015-09-29 08:55 -0700
Re: Spurious diagnostic messages supercat@casperkitty.com - 2015-09-29 10:22 -0700
Re: Spurious diagnostic messages Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-04 23:42 -0700
Re: Spurious diagnostic messages supercat@casperkitty.com - 2015-10-05 09:41 -0700
Re: Spurious diagnostic messages Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-09 13:22 -0700
Re: Spurious diagnostic messages David Brown <david.brown@hesbynett.no> - 2015-09-29 22:28 +0200
Re: Spurious diagnostic messages Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-05 00:14 -0700
Re: Spurious diagnostic messages David Brown <david.brown@hesbynett.no> - 2015-10-05 10:30 +0200
Re: Spurious diagnostic messages supercat@casperkitty.com - 2015-10-05 10:06 -0700
Re: Spurious diagnostic messages David Brown <david.brown@hesbynett.no> - 2015-10-06 09:23 +0200
Re: Spurious diagnostic messages supercat@casperkitty.com - 2015-10-06 11:18 -0700
Re: Spurious diagnostic messages Keith Thompson <kst-u@mib.org> - 2015-10-06 14:29 -0700
Re: Spurious diagnostic messages supercat@casperkitty.com - 2015-10-06 15:33 -0700
Re: Spurious diagnostic messages David Brown <david.brown@hesbynett.no> - 2015-10-07 12:35 +0200
Re: Spurious diagnostic messages David Brown <david.brown@hesbynett.no> - 2015-10-07 10:57 +0200
Re: Spurious diagnostic messages supercat@casperkitty.com - 2015-10-07 07:09 -0700
Re: Spurious diagnostic messages David Brown <david.brown@hesbynett.no> - 2015-10-08 09:28 +0200
Re: Spurious diagnostic messages supercat@casperkitty.com - 2015-10-08 01:45 -0700
Re: Spurious diagnostic messages glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-10-08 09:42 +0000
Re: Spurious diagnostic messages supercat@casperkitty.com - 2015-10-08 09:42 -0700
Re: Spurious diagnostic messages Keith Thompson <kst-u@mib.org> - 2015-10-07 09:40 -0700
Re: Spurious diagnostic messages David Brown <david.brown@hesbynett.no> - 2015-10-08 09:44 +0200
Re: Spurious diagnostic messages Keith Thompson <kst-u@mib.org> - 2015-10-08 08:25 -0700
Re: Spurious diagnostic messages David Brown <david.brown@hesbynett.no> - 2015-10-08 20:36 +0200
Re: Spurious diagnostic messages Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-08 13:28 -0700
Re: Spurious diagnostic messages Bartc <bc@freeuk.com> - 2015-10-08 22:21 +0100
Re: Spurious diagnostic messages supercat@casperkitty.com - 2015-10-08 14:33 -0700
Re: Spurious diagnostic messages David Brown <david.brown@hesbynett.no> - 2015-10-09 10:24 +0200
Re: Spurious diagnostic messages supercat@casperkitty.com - 2015-10-09 08:35 -0700
Re: Spurious diagnostic messages David Brown <david.brown@hesbynett.no> - 2015-10-11 15:18 +0200
Re: Spurious diagnostic messages supercat@casperkitty.com - 2015-10-11 14:53 -0700
Re: Spurious diagnostic messages David Brown <david.brown@hesbynett.no> - 2015-10-12 09:17 +0200
Re: Spurious diagnostic messages supercat@casperkitty.com - 2015-10-12 00:37 -0700
Re: Spurious diagnostic messages Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-10 00:31 -0700
Re: Spurious diagnostic messages Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-10 10:50 +0100
Re: Spurious diagnostic messages Bartc <bc@freeuk.com> - 2015-10-10 11:01 +0100
Re: Spurious diagnostic messages Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-10 03:43 -0700
Re: Spurious diagnostic messages supercat@casperkitty.com - 2015-10-10 13:26 -0700
Re: Spurious diagnostic messages supercat@casperkitty.com - 2015-10-10 13:34 -0700
Re: Spurious diagnostic messages David Brown <david.brown@hesbynett.no> - 2015-10-11 15:25 +0200
Re: Spurious diagnostic messages Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-14 07:43 -0700
Re: Spurious diagnostic messages David Brown <david.brown@hesbynett.no> - 2015-10-14 17:00 +0200
csiph-web