playfunc.c:524: error: initializer element is not constant

Discussion in 'C Programming' started by Levi Campbell, Feb 11, 2006.

  1. Hi, I'm trying to debug an app someone else wrote called eMixer. Here's
    the log contents:

    cc -O3 -funroll-loops -c -o main.o main.c

    cc -O3 -funroll-loops -c -o nctgui.o nctgui.c

    cc -O3 -funroll-loops -c -o mixer.o mixer.c

    mixer.c: In function `open_soundcard_alsa':

    mixer.c:201: warning: passing arg 3 of
    `snd_pcm_hw_params_set_rate_near' makes pointer from integer without a
    cast

    cc -O3 -funroll-loops -c -o getlopt.o getlopt.c

    cc -O3 -funroll-loops -c -o plstfunc.o plstfunc.c

    cc -O3 -funroll-loops -c -o playfunc.o playfunc.c

    playfunc.c: In function `do_autofade':

    playfunc.c:524: error: initializer element is not constant

    playfunc.c:524: error: (near initialization for `checkmode[0][0]')

    playfunc.c:524: error: initializer element is not constant

    playfunc.c:524: error: (near initialization for `checkmode[0][1]')

    playfunc.c:524: error: initializer element is not constant

    playfunc.c:524: error: (near initialization for `checkmode[0]')


    And the line in question looks like this:

    static int checkmode[3][2]={(0,0,0),(0,0,0)};

    To try and solve this problem, I've commented out the static part and
    while the program compiles, it segfaults when you try and run it. I've
    also tried adding -ansi to the CFLAGS but that doesn't work. When I
    searched the web, I got lots of hits about other people having the same
    problem, but the code wasen't close enough that I could get an idea of
    how thhe problem was fixed. does anyone have any ideas about what I
    need to do here? Thank you for your time.
     
    Levi Campbell, Feb 11, 2006
    #1
    1. Advertising

  2. Levi Campbell said:

    > And the line in question looks like this:
    >
    > static int checkmode[3][2]={(0,0,0),(0,0,0)};


    That should be:

    static int checkmode[3][2] = {{0, 0}, {0, 0}, {0, 0}};

    or simply:

    static int checkmode[3][2] = {0};

    or even (because it's static):

    static int checkmode[3][2];

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
     
    Richard Heathfield, Feb 11, 2006
    #2
    1. Advertising

  3. Holy crap, it worked and it didn't segfault! Thank you.

    Richard Heathfield wrote:
    > Levi Campbell said:
    >
    > > And the line in question looks like this:
    > >
    > > static int checkmode[3][2]={(0,0,0),(0,0,0)};

    >
    > That should be:
    >
    > static int checkmode[3][2] = {{0, 0}, {0, 0}, {0, 0}};
    >
    > or simply:
    >
    > static int checkmode[3][2] = {0};
    >
    > or even (because it's static):
    >
    > static int checkmode[3][2];
    >
    > --
    > Richard Heathfield
    > "Usenet is a strange place" - dmr 29/7/1999
    > http://www.cpax.org.uk
    > email: rjh at above domain (but drop the www, obviously)
     
    Levi Campbell, Feb 11, 2006
    #3
  4. Levi Campbell

    Flash Gordon Guest

    Levi Campbell wrote:

    <snip>

    > cc -O3 -funroll-loops -c -o mixer.o mixer.c
    >
    > mixer.c: In function `open_soundcard_alsa':
    >
    > mixer.c:201: warning: passing arg 3 of
    > `snd_pcm_hw_params_set_rate_near' makes pointer from integer without a
    > cast


    Something Richard did not mention is that this is a potentially very
    serious warning and you really should track it down and fix the issue.
    However, do *not* fix it by simply adding a cast, that would almost
    certainly be the *wrong* thing to do.

    <snip>

    > also tried adding -ansi to the CFLAGS but that doesn't work. When I


    <OT>
    That is a good switch to use. You might also want to add the following
    -pedantic -Wall -O
    These switches have the potential to catch a lot more problems in the code.
    </OT>
    --
    Flash Gordon
    Living in interesting times.
    Although my email address says spam, it is real and I read it.
     
    Flash Gordon, Feb 11, 2006
    #4
    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,372
    Kevin Easton
    Jul 30, 2003
  2. Replies:
    3
    Views:
    633
    Wade Ward
    Oct 21, 2007
  3. Gowtham
    Replies:
    16
    Views:
    811
    Szabolcs Borsanyi
    May 9, 2008
  4. TheFlyingDutchman

    Tiny C error - initializer element is not constant

    TheFlyingDutchman, Jan 25, 2011, in forum: C Programming
    Replies:
    4
    Views:
    982
    TheFlyingDutchman
    Jan 25, 2011
  5. Bart Vandewoestyne

    error: initializer element is not constant

    Bart Vandewoestyne, Oct 3, 2012, in forum: C Programming
    Replies:
    5
    Views:
    592
    Nobody
    Oct 4, 2012
Loading...

Share This Page