From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Ralf Gütlein" To: "gcc-help" Subject: initializing ints with mem refs (ANSI C??) Date: Thu, 02 Mar 2000 02:46:00 -0000 Message-id: <200003021046.LAA11366@server5.aranea.net> X-SW-Source: 2000-03/msg00010.html 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 From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Ralf Gütlein" To: "gcc-help" Subject: initializing ints with mem refs (ANSI C??) Date: Sat, 01 Apr 2000 00:00:00 -0000 Message-ID: <200003021046.LAA11366@server5.aranea.net> X-SW-Source: 2000-q1/msg00320.html Message-ID: <20000401000000.6QChtHudvqv7ds-LM92v177ufVyuYEfvTyOE2bD2P28@z> 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