public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* initialization of static struct with GCC 3.0.1
@ 2001-09-18  0:34 Thanh-Lam NGUYEN
  0 siblings, 0 replies; only message in thread
From: Thanh-Lam NGUYEN @ 2001-09-18  0:34 UTC (permalink / raw)
  To: gcc-help

Hi,
here is the code I tried to compile :
---------------------------------------------------
#include <stdlib.h>
#include <stdio.h>

typedef union {
    long l;
    struct {
        short ll;
        short lh;
    };
} tunion;

const tunion initunion={ 0x11223344l };

int main( void )
{
    static tunion t=initunion;

    printf( "t.l  : %#lx\nt.ll : %#lx\nt.lh : %#lx\n", t.l, t.ll, t.lh
);
}
---------------------------------------------------
nothing very special.
Here's the message I get :

>gcc union.c
union.c: In function `main':
union.c:16: initializer element is not constant
Exit 1


When I remove the  "static" prefix, it compiles fine.

What I want to do is to initialize my union once at the begining of a
function and from then,
I want it to retain its value each time I call the function.

Is there another way to do it ?
Currently I use a if statement to do it, but I need to optimize my code
to gain speed.

Thanks for any reply
Thanh lam NGUYEN

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2001-09-18  0:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-18  0:34 initialization of static struct with GCC 3.0.1 Thanh-Lam NGUYEN

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