public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* `initializer element is not constant' issue
@ 2001-08-21 14:23 Gigi Sullivan
  2001-08-22  0:33 ` Alexandre Oliva
  0 siblings, 1 reply; 5+ messages in thread
From: Gigi Sullivan @ 2001-08-21 14:23 UTC (permalink / raw)
  To: gcc-help

Aiee :)

   Hello!

   I'd like to initialize global variables outside of
   functions (as usual) in a slightly different manner;
   let's consider the attached file, please.

   Everything should be ok, but I get 

   `initializer element is not constant' error from the compiler.

   Is there a way to work around this, please? [1]

bye bye && thanks!

                     -- gg sullivan

[1]: I cannot/don't want to put these declaration inside some
functions.

-- 
Lorenzo Cavallaro	`Gigi Sullivan' <sullivan@sikurezza.org>

Until I loved, life had no beauty;
I did not know I lived until I had loved. (Theodor Korner)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: `initializer element is not constant' issue
  2001-08-21 14:23 `initializer element is not constant' issue Gigi Sullivan
@ 2001-08-22  0:33 ` Alexandre Oliva
  2001-08-22  3:42   ` Gigi Sullivan
  0 siblings, 1 reply; 5+ messages in thread
From: Alexandre Oliva @ 2001-08-22  0:33 UTC (permalink / raw)
  To: Gigi Sullivan; +Cc: gcc-help

On Aug 21, 2001, Gigi Sullivan <sullivan@sikurezza.org> wrote:

>    Everything should be ok, but I get 

>    `initializer element is not constant' error from the compiler.

>    Is there a way to work around this, please? [1]

I'm afraid initializers of global variables cannot contain function
calls in C.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: `initializer element is not constant' issue
  2001-08-22  0:33 ` Alexandre Oliva
@ 2001-08-22  3:42   ` Gigi Sullivan
  2001-08-23  8:00     ` Gigi Sullivan
  0 siblings, 1 reply; 5+ messages in thread
From: Gigi Sullivan @ 2001-08-22  3:42 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: gcc-help

Aiee :)

   Hello!

On Wed, Aug 22, 2001 at 04:29:48AM -0300, Alexandre Oliva wrote:
> >    `initializer element is not constant' error from the compiler.
> 
> >    Is there a way to work around this, please? [1]
> 
> I'm afraid initializers of global variables cannot contain function
> calls in C.

   Hep, as I supposed :) ...
   Is this either a standard or just a not-implemented
   feature by gcc?
   
   Do you have any advice about doing something like that?

   I need to initialize global vars while filling some table,
   but I don't want to fill this table within function call ...

   Is it definetly just impossible?

bye bye && thanks!

                     -- gg sullivan

-- 
Lorenzo Cavallaro	`Gigi Sullivan' <sullivan@sikurezza.org>

Until I loved, life had no beauty;
I did not know I lived until I had loved. (Theodor Korner)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: `initializer element is not constant' issue
  2001-08-22  3:42   ` Gigi Sullivan
@ 2001-08-23  8:00     ` Gigi Sullivan
  2001-08-23 23:39       ` Alexandre Oliva
  0 siblings, 1 reply; 5+ messages in thread
From: Gigi Sullivan @ 2001-08-23  8:00 UTC (permalink / raw)
  To: aoliva; +Cc: gcc-help

Aiee :)

   Hello!

On Wed, Aug 22, 2001 at 12:15:59PM +0200, Gigi Sullivan wrote:
> On Wed, Aug 22, 2001 at 04:29:48AM -0300, Alexandre Oliva wrote:
> > >    `initializer element is not constant' error from the compiler.
> > 
> > >    Is there a way to work around this, please? [1]
> > 
> > I'm afraid initializers of global variables cannot contain function
> > calls in C.
> 
>    Is it definetly just impossible?

   Ok, I found something that could be acceptable to me, a sorta
   of workaround (even, oviously, is not just what I wanted to
   do ;))

   Any comments, hints about this (3 really small C filefollows)?

   Basically I used __attribute__((constructor)) gcc extension.
   I'm aware that this is not a really portable feature (it's not
   standard) but I think that many people are using gcc right now,
   am I right? :)

-- 
Lorenzo Cavallaro	`Gigi Sullivan' <sullivan@sikurezza.org>

Until I loved, life had no beauty;
I did not know I lived until I had loved. (Theodor Korner)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: `initializer element is not constant' issue
  2001-08-23  8:00     ` Gigi Sullivan
@ 2001-08-23 23:39       ` Alexandre Oliva
  0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Oliva @ 2001-08-23 23:39 UTC (permalink / raw)
  To: Gigi Sullivan; +Cc: gcc-help

On Aug 23, 2001, Gigi Sullivan <sullivan@sikurezza.org> wrote:

>> Is it definetly just impossible?

>    Basically I used __attribute__((constructor)) gcc extension.

Yep, that's the only way to do it in C.  You can switch to C++, that
introduces the ability to do dynamic initialization of global
variables.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-08-23 23:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-21 14:23 `initializer element is not constant' issue Gigi Sullivan
2001-08-22  0:33 ` Alexandre Oliva
2001-08-22  3:42   ` Gigi Sullivan
2001-08-23  8:00     ` Gigi Sullivan
2001-08-23 23:39       ` Alexandre Oliva

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).