* initializing ints with mem refs (ANSI C??)
@ 2000-03-02 2:46 Ralf Gütlein
2000-04-01 0:00 ` Ralf Gütlein
0 siblings, 1 reply; 2+ messages in thread
From: Ralf Gütlein @ 2000-03-02 2:46 UTC (permalink / raw)
To: gcc-help
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* initializing ints with mem refs (ANSI C??)
2000-03-02 2:46 initializing ints with mem refs (ANSI C??) Ralf Gütlein
@ 2000-04-01 0:00 ` Ralf Gütlein
0 siblings, 0 replies; 2+ messages in thread
From: Ralf Gütlein @ 2000-04-01 0:00 UTC (permalink / raw)
To: gcc-help
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2000-04-01 0:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-02 2:46 initializing ints with mem refs (ANSI C??) Ralf Gütlein
2000-04-01 0:00 ` Ralf Gütlein
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).