public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "gnu at behdad dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/38295]  New: Support pointer difference as constant in static initializer
Date: Thu, 27 Nov 2008 18:20:00 -0000	[thread overview]
Message-ID: <bug-38295-8802@http.gcc.gnu.org/bugzilla/> (raw)

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


             reply	other threads:[~2008-11-27 18:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-27 18:20 gnu at behdad dot org [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-38295-8802@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).