build error on Linux - initializer element is not computable at load time

Discussion in 'C Programming' started by B. Wood, Oct 16, 2003.

  1. B. Wood

    B. Wood Guest

    I have a small program (see below) that demonstrates an error I am
    getting when I build the program on a linux platform.

    I first initialize an unsigned char array (lines 16).

    I then initialize my array of my typedeffed structure (dataStruct)
    (lines 18-24). I use my initialized unsigned character array to
    initialize the unsigned character pointer member of the structure
    (line 21).

    I then do a for loop, dumping the initialized data in the array of
    structures.

    This compiles fine under Windows 2000 using Microsoft 32-bit C/C++
    Optimizing Compiler Version 12.00.8804, with no errors or warnings and
    executes as expected.

    On a linux platform, running Red Hat Linux 7.1 2.96-98 using gcc
    version 2.96 20000731 I get the following error:

    - initializer element is not computable at load time

    I get the error on line 21 where I initialize my structures unsigned
    char pointer member with the initialized unsigned character array.

    I get the same error on line 23 where the closing brace of the
    structure member initialize is.

    Does anyone have any ideas on what this could be.

    1 typedef struct dataStruct_
    2 {
    3 unsigned char * buffer;
    4 unsigned int length;
    5 }
    6 dataStruct;
    7
    8 int
    9 main
    10 (
    11 int argc,
    12 char * argv[]
    13 )
    14 {
    15
    16 unsigned char buffer[] = { 1,2,3,4,5 };
    17
    18 dataStruct data[] =
    19 {
    20 {
    21 buffer,
    22 sizeof(buffer)
    23 }
    24 };
    25
    26 int i;
    27
    28 for (i = 0; i < 5; i++)
    29 {
    30 printf("%d\n", data[0].buffer);
    31 }
    32 printf("data size = %d\n", data[0].length);
    33
    34 return (EXIT_SUCCESS);
    35
    36 }
    B. Wood, Oct 16, 2003
    #1
    1. Advertising

  2. On 16 Oct 2003 09:39:48 -0700, (B. Wood) wrote:

    >I have a small program (see below) that demonstrates an error I am
    >getting when I build the program on a linux platform.
    >
    >I first initialize an unsigned char array (lines 16).
    >
    >I then initialize my array of my typedeffed structure (dataStruct)
    >(lines 18-24). I use my initialized unsigned character array to
    >initialize the unsigned character pointer member of the structure
    >(line 21).
    >
    >I then do a for loop, dumping the initialized data in the array of
    >structures.
    >
    >This compiles fine under Windows 2000 using Microsoft 32-bit C/C++
    >Optimizing Compiler Version 12.00.8804, with no errors or warnings and
    >executes as expected.


    Try it with compiler extensions disabled (I'm using a later version of the
    compiler but I'm pretty sure yours will behave in the same way).

    D:\source\clc>cl /Za 031016_1.c
    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
    Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

    031016_1.c
    031016_1.c(21) : error C2093: 'buffer' : cannot be initialized using address
    of automatic variable '
    buffer'
    031016_1.c(16) : see declaration of 'buffer'
    031016_1.c(21) : error C2097: illegal initialization
    031016_1.c(34) : error C2065: 'EXIT_SUCCESS' : undeclared identifier

    You'll need to replace the initialization with a post-inititialization
    assignment.

    (And fix the EXIT_SUCCESS error, and the missing prototype for printf).

    -- Mat.
    Mathew Hendry, Oct 16, 2003
    #2
    1. Advertising

  3. Re: build error on Linux - initializer element is not computable atload time

    On Thu, 16 Oct 2003 17:56:24 +0100
    Mathew Hendry <> wrote:

    [snip]

    >
    > (And fix the EXIT_SUCCESS error, and the missing prototype for
    > printf).
    >
    > -- Mat.
    >


    #include <stdio.h>
    #include <stdlib.h>

    :)

    --
    --
    ThE_TemPLaR
    Eddahbi Karim, Oct 17, 2003
    #3
  4. B. Wood

    B. Wood Guest

    Eddahbi Karim <> wrote in message news:<>...
    > On Thu, 16 Oct 2003 17:56:24 +0100
    > Mathew Hendry <> wrote:
    >
    > [snip]
    >
    > >
    > > (And fix the EXIT_SUCCESS error, and the missing prototype for
    > > printf).
    > >
    > > -- Mat.
    > >

    >
    > #include <stdio.h>
    > #include <stdlib.h>
    >
    > :)
    >
    > --


    Yes, I realize I didn't include in my posting the includes and some
    other things, I just wanted to post the heart of the code.

    >Try it with compiler extensions disabled (I'm using a later version

    of the
    >compiler but I'm pretty sure yours will behave in the same way).
    >
    >D:\source\clc>cl /Za 031016_1.c
    >Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for

    80x86
    >Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.


    When you say try compiler extensions, you do mean the gcc compiler on
    the Linux platorm right. Because the next part of your post shows you
    running the Microsoft compiler. I am not having any problems with
    that compiler. It is the gcc compiler on the Linux box that has the
    problem.
    B. Wood, Oct 17, 2003
    #4
  5. On 17 Oct 2003 07:30:22 -0700, (B. Wood) wrote:

    >Mathew Hendry <> wrote:
    >
    >>Try it with compiler extensions disabled (I'm using a later version
    >>of the compiler but I'm pretty sure yours will behave in the same way).
    >>
    >>D:\source\clc>cl /Za 031016_1.c
    >>Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
    >>Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

    >
    >When you say try compiler extensions, you do mean the gcc compiler on
    >the Linux platorm right. Because the next part of your post shows you
    >running the Microsoft compiler. I am not having any problems with
    >that compiler. It is the gcc compiler on the Linux box that has the
    >problem.


    I'm saying that it only works on your Microsoft compiler because you have
    compiler extensions enabled. The /Za option (as above) turns them off and
    forces the compiler to report the error - the code is not portable and gcc
    is correct to complain.

    -- Mat.
    Mathew Hendry, Oct 17, 2003
    #5
  6. B. Wood

    Kevin Bracey Guest

    In message <>
    Mathew Hendry <> wrote:

    > I'm saying that it only works on your Microsoft compiler because you have
    > compiler extensions enabled. The /Za option (as above) turns them off and
    > forces the compiler to report the error - the code is not portable and gcc
    > is correct to complain.


    That's assuming we're trying to write C90, by the way. The original poster's
    code is valid C99, so a modern version of gcc with its partial C99 support
    will probably handle it.

    --
    Kevin Bracey, Principal Software Engineer
    Tematic Ltd Tel: +44 (0) 1223 503464
    182-190 Newmarket Road Fax: +44 (0) 1223 503458
    Cambridge, CB5 8HE, United Kingdom WWW: http://www.tematic.com/
    Kevin Bracey, Oct 17, 2003
    #6
  7. Kevin Bracey <> wrote:

    >In message <>
    > Mathew Hendry <> wrote:
    >
    >> I'm saying that it only works on your Microsoft compiler because you have
    >> compiler extensions enabled. The /Za option (as above) turns them off and
    >> forces the compiler to report the error - the code is not portable and gcc
    >> is correct to complain.

    >
    >That's assuming we're trying to write C90, by the way. The original poster's
    >code is valid C99, so a modern version of gcc with its partial C99 support
    >will probably handle it.


    gcc 3.2 does.
    --
    Irrwahn
    ()
    Irrwahn Grausewitz, Oct 17, 2003
    #7
  8. "B. Wood" <> wrote in message
    news:...
    > I have a small program (see below) that demonstrates an error I am
    > getting when I build the program on a linux platform.
    >
    > I first initialize an unsigned char array (lines 16).
    >
    > I then initialize my array of my typedeffed structure (dataStruct)
    > (lines 18-24). I use my initialized unsigned character array to
    > initialize the unsigned character pointer member of the structure
    > (line 21).


    (snip)

    > 16 unsigned char buffer[] = { 1,2,3,4,5 };
    > 17
    > 18 dataStruct data[] =


    You could also make buffer static, if that works with the logic of the
    program.

    If you don't change the values, that should work. Though not changing the
    data in a buffer would be unusual.

    -- glen
    Glen Herrmannsfeldt, Oct 17, 2003
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Todd Nathan

    Error: "initializer element is not constant"

    Todd Nathan, Jul 30, 2003, in forum: C Programming
    Replies:
    2
    Views:
    19,327
    Kevin Easton
    Jul 30, 2003
  2. Clint Olsen

    Initializer element not computable at load time

    Clint Olsen, Oct 17, 2003, in forum: C Programming
    Replies:
    6
    Views:
    1,320
    Irrwahn Grausewitz
    Oct 18, 2003
  3. bingfeng
    Replies:
    4
    Views:
    2,718
    bingfeng
    Jun 2, 2005
  4. bingfeng
    Replies:
    3
    Views:
    563
    Chris Torek
    Jun 6, 2005
  5. copx

    not computable at load time?

    copx, Jul 31, 2007, in forum: C Programming
    Replies:
    2
    Views:
    495
Loading...

Share This Page