public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Ralf Gütlein" <ralf.guetlein@aranea.de>
To: "gcc-help" <gcc-help@gcc.gnu.org>
Subject: initializing ints with mem refs (ANSI C??)
Date: Sat, 01 Apr 2000 00:00:00 -0000	[thread overview]
Message-ID: <200003021046.LAA11366@server5.aranea.net> (raw)
Message-ID: <20000401000000.6QChtHudvqv7ds-LM92v177ufVyuYEfvTyOE2bD2P28@z> (raw)

I'm used to use gcc for developing embedded systems' software.
In an ongoing redesign i was urged to use a controller for
which no gcc port is available (NEC 78k0 derivative), so I
switched to the IAR compiler (commercial product). During
porting the software to the new target, I ran into several
problems. All of them could be solved but one:

In my source code I extensively used constructs like

const int object = 0;
int a[2] = {1, (const int)&object;};

(I know this is not portable when the internal representation of
addresses is other than the size of int. But it lead to a very
elegant and code efective solution to my coding problem.)

But instead of issueing a warning (sth. like 'loosing
precision') the IAR compiler complains about 'constant
initializer expected' and aborts.
Gcc swallowed the code with no problems.

My question:

What does the ANSI standard demand here? In my eyes the
initializer **is** constant (i.e. can be evaluated at compile
time). The same IAR compiler does not moan when I use

int * const a[2] = {(int *const)1, &object };

instead.

Is ANSI precise here? Or is gcc's implemenation more relaxed
than IAR's?

Regards,

Ralf

             reply	other threads:[~2000-04-01  0:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-03-02  2:46 Ralf Gütlein [this message]
2000-04-01  0:00 ` Ralf Gütlein

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=200003021046.LAA11366@server5.aranea.net \
    --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).