public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/38295]  New: Support pointer difference as constant in static initializer
@ 2008-11-27 18:20 gnu at behdad dot org
  2008-11-27 18:30 ` [Bug c/38295] " pinskia at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: gnu at behdad dot org @ 2008-11-27 18:20 UTC (permalink / raw)
  To: gcc-bugs

The feature I'm proposing is not supported by the C standard, so I'm proposing
a gcc extension.

I am wondering if it's possible to make the difference of two function pointer
be a constant value if the two functions are defined as static and in the same
file.  That would allow for function pointer tables that live in .rodata
instead of .data.  Something like:

#include <stdio.h>

typedef int (*func_t) (void);

static int func_base (void)
{
  return 0;
}

static int func0 (void)
{
  return 0;
}

static int func1 (void)
{
  return 1;
}

size_t funcs[] = {
  func0 - func_base,
  func1 - func_base
};

int
main (void)
{
  int i;

  for (i = 0; i < 2; i++)
    printf ("%d: %d\n", i, ((func_t)(funcs[i] + func_base))());
}


-- 
           Summary: Support pointer difference as constant in static
                    initializer
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: enhancement
          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=38295


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-11-27 18:56 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-27 18:20 [Bug c/38295] New: Support pointer difference as constant in static initializer gnu at behdad dot org
2008-11-27 18:30 ` [Bug c/38295] " pinskia at gcc dot gnu dot org
2008-11-27 18:32 ` gnu at behdad dot org
2008-11-27 18:33 ` gnu at behdad dot org
2008-11-27 18:34 ` pinskia at gcc dot gnu dot org
2008-11-27 18:36 ` gnu at behdad dot org
2008-11-27 18:53 ` pinskia at gcc dot gnu dot org
2008-11-27 18:54 ` pinskia at gcc dot gnu dot org
2008-11-27 18:56 ` gnu at behdad dot org

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).