From: Ralf Guetlein <ralf.guetlein@aranea.de>
To: gcc-help@gcc.gnu.org
Subject: [Fwd: Re: initializing ints with mem refs (ANSI C??)]
Date: Sat, 01 Apr 2000 00:00:00 -0000 [thread overview]
Message-ID: <38C299F4.EDC79545@aranea.de> (raw)
Message-ID: <20000401000000.QE4rPPcvsItREERIAARzBGfgNWdx6PsIUqJ-S0hjkqs@z> (raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2180 bytes --]
Moogla,
thank you for your reply
>
> Ralf Gütlein wrote:
>
> > const int object = 0;
> > int a[2] = {1, (const int)&object;};
Moogla wrote:
> Is there any problem with:
> const int object = 0;
> int a[2];
> a[0] = 1;
> a[1] = (const int) &object;
I should have written:
enum {item1, item2, item3, item4};
const int menu1[] = {item1, item2, item3};
const int menu2[] = {item4, (const int)menu1};
What I intended to do is generating a linked list in ROM
to implement a hierachical menu structure. In gcc this
is no problem, as I stated earlier.
>
> > What does the ANSI standard demand here?
>
> ANSI only requires it to minimally be a constant expression, one that
> can be evaluated at compile time. Of course, we know the address of
> object at compile time, but strictly, it's not a constant.
The difference between 'item1' and '(const int)menu1' is that the latter
is evaluated at *link* time. So you are right in that it is not a
*compile* time constant. This is no problem for gcc.
But IMO this should be generally no problem because
typedef void* PVOID;
enum {item1, item2, item3, item4};
const PVOID menu1[] = {(PVOID)item1, (PVOID)item2, (PVOID)item3};
const PVOID menu2[] = {(PVOID)item4, (PVOID)menu1};
works with both compilers, although '(PVOID)menu1' again can be
calculated only at link time.
(The assembler listing issued by gcc is exactly the same for both
of the above contructs, and the IAR assembler listing for the
latter one is functionally identical to those made by gcc.)
> a subexpression elimination pass which rejects address references, and
> this pass is used to verify aggregate initializers. Also, IAR may feel
> it wants to move addresses of variables around in the data segment if
> it's feeling particularly optimizationy or whatever. GCC, oth, only
> resolves the initialization until it knows what the final value will be.
> I don't think you can count on that in future releases of EGCS, though.
>
I guess the compiler behaviour in these cases depends in no way on
any kind of optimization. It's merely a restriction implemented by
the compiler writers (with or without intent).
> moogla
Thanks again. Regards,
Ralf
next reply other threads:[~2000-04-01 0:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-03-05 9:29 Ralf Guetlein [this message]
2000-04-01 0:00 ` Ralf Guetlein
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=38C299F4.EDC79545@aranea.de \
--to=ralf.guetlein@aranea.de \
--cc=gcc-help@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).