public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/38354] New: Spurious error: initializer element is not computable at load time
@ 2008-12-01 21:05 gnu at behdad dot org
2008-12-01 23:35 ` [Bug c/38354] " jakub at gcc dot gnu dot org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: gnu at behdad dot org @ 2008-12-01 21:05 UTC (permalink / raw)
To: gcc-bugs
The following code is from gcc docs and works as expected:
#include <stdio.h>
int
main (int argc, char **argv)
{
static const int array[] = { &&foo-&&foo, &&bar-&&foo, &&hack-&&foo };
int i = argc - 1;
goto *(array[i]+&&foo);
foo:
printf ("foo\n");
return 0;
bar:
printf ("bar\n");
return 0;
hack:
printf ("hack\n");
return 0;
}
However, if I change the array type from:
static const int array[] = { &&foo-&&foo, &&bar-&&foo, &&hack-&&foo };
to:
static const void *array[] = { &&foo-&&foo, &&bar-&&foo, &&hack-&&foo };
I get the error:
label-value.c:6: error: initializer element is not computable at load time
This doesn't make any sense to me.
--
Summary: Spurious error: initializer element is not computable at
load time
Product: gcc
Version: 4.3.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gnu at behdad dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38354
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/38354] Spurious error: initializer element is not computable at load time
2008-12-01 21:05 [Bug c/38354] New: Spurious error: initializer element is not computable at load time gnu at behdad dot org
@ 2008-12-01 23:35 ` jakub at gcc dot gnu dot org
2008-12-01 23:39 ` gnu at behdad dot org
2010-08-17 6:28 ` adam at consulting dot net dot nz
2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu dot org @ 2008-12-01 23:35 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from jakub at gcc dot gnu dot org 2008-12-01 23:33 -------
What's the rationale for using a pointer type for something that is integral
(difference of 2 pointers)?
I don't see why we should support that as a valid constant initializer.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38354
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/38354] Spurious error: initializer element is not computable at load time
2008-12-01 21:05 [Bug c/38354] New: Spurious error: initializer element is not computable at load time gnu at behdad dot org
2008-12-01 23:35 ` [Bug c/38354] " jakub at gcc dot gnu dot org
@ 2008-12-01 23:39 ` gnu at behdad dot org
2010-08-17 6:28 ` adam at consulting dot net dot nz
2 siblings, 0 replies; 4+ messages in thread
From: gnu at behdad dot org @ 2008-12-01 23:39 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from gnu at behdad dot org 2008-12-01 23:38 -------
It's not a useful use case, agreed, but I don't see how that affects the
computability of a value at "load time", whatever that means. It did trick me:
I was converting a vtable to use label values, and before converting the
function pointer type of the array to int, I tried a compile and got the error.
I didn't expect the error to go away if I replace the function pointer type
with an int. To my surprise, it did.
What I'm saying is that the statement in the error message is false.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38354
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/38354] Spurious error: initializer element is not computable at load time
2008-12-01 21:05 [Bug c/38354] New: Spurious error: initializer element is not computable at load time gnu at behdad dot org
2008-12-01 23:35 ` [Bug c/38354] " jakub at gcc dot gnu dot org
2008-12-01 23:39 ` gnu at behdad dot org
@ 2010-08-17 6:28 ` adam at consulting dot net dot nz
2 siblings, 0 replies; 4+ messages in thread
From: adam at consulting dot net dot nz @ 2010-08-17 6:28 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1574 bytes --]
------- Comment #3 from adam at consulting dot net dot nz 2010-08-17 06:28 -------
AMD64 non-large code model. Functions occupy lower 2GB of the address space.
Cannot compile an array of 32-bit function addresses:
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
void fn() {
printf("Hello, World\n");
}
uint32_t computable_at_load_time_a[]={fn};
uint32_t computable_at_load_time_b[]={(uint32_t) (ptrdiff_t) fn};
int main() {
return 0;
}
$ gcc -m32 computable_at_load_time.c
computable_at_load_time.c:9: warning: initialization makes integer from pointer
without a cast
$ gcc computable_at_load_time.c
computable_at_load_time.c:9: warning: initialization makes integer from pointer
without a cast
computable_at_load_time.c:9: error: initializer element is not computable at
load time
computable_at_load_time.c:9: error: (near initialization for
computable_at_load_time_a[0])
computable_at_load_time.c:10: error: initializer element is not constant
computable_at_load_time.c:10: error: (near initialization for
computable_at_load_time_b[0])
The very good reason for wanting to compile a table of 32-bit function pointers
is to halve the data cache footprint of threaded code.
--
adam at consulting dot net dot nz changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |adam at consulting dot net
| |dot nz
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38354
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-08-17 6:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-01 21:05 [Bug c/38354] New: Spurious error: initializer element is not computable at load time gnu at behdad dot org
2008-12-01 23:35 ` [Bug c/38354] " jakub at gcc dot gnu dot org
2008-12-01 23:39 ` gnu at behdad dot org
2010-08-17 6:28 ` adam at consulting dot net dot nz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).