This is the mail archive of the
mailing list for the GCC project.
Re: Why does gcc generate const local array on stack?
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: lh_mouse <lh_mouse at 126 dot com>
- Cc: Bingfeng Mei <bingfeng dot mei at broadcom dot com>, gcc <gcc at gcc dot gnu dot org>
- Date: Wed, 20 Apr 2016 18:51:09 +0100
- Subject: Re: Why does gcc generate const local array on stack?
- Authentication-results: sourceware.org; auth=none
- References: <CAAvcwYdM4AR0JjN4pY=xndyYAmgLTQ8i54EzeUrj4L=wtGBAog at mail dot gmail dot com> <31a6f6bf dot e3788 dot 15434b9ee28 dot Coremail dot lh_mouse at 126 dot com>
On 20 April 2016 at 18:31, lh_mouse wrote:
> I tend to say clang is wrong here.
If you can't detect the difference then it is a valid transformation.
> Your identifier 'a' has no linkage. Your object designated by 'a' does not have a storage-class specifier.
> So it has automatic storage duration and 6.2.4/7 applies: 'If the scope is entered recursively, a new instance of the object is created each time.'
How do you tell the difference between a const array that is recreated
each time and one that isn't?
> Interesting enough, ISO C doesn't say whether distinct objects should have distinct addresses.
> It is worth noting that this is explicitly forbidden in ISO C++ because distinct complete objects shall have distinct addresses:
If the object's address doesn't escape from the function then I can't
think of a way to tell the difference.