public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Thanh-Lam NGUYEN <nguyen56@sxb.bsf.alcatel.fr>
To: gcc-help@gcc.gnu.org
Subject: initialization of static struct with GCC 3.0.1
Date: Tue, 18 Sep 2001 00:34:00 -0000	[thread overview]
Message-ID: <3BA6F90C.7EDFC9CE@sxb.bsf.alcatel.fr> (raw)

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

                 reply	other threads:[~2001-09-18  0:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=3BA6F90C.7EDFC9CE@sxb.bsf.alcatel.fr \
    --to=nguyen56@sxb.bsf.alcatel.fr \
    --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).