C99

This is a discussion on C99 within the Linux Programming forums, part of the Platform Specific Boards category; I am using gcc 4.4.3 version i am getting a compile error :- error: variable-sized object may not be initialized ...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    6

    C99

    I am using gcc 4.4.3 version
    i am getting a compile error :- error: variable-sized object may not be initialized

    Code:
    double dev_dp[num_app][2] = {{0.30 ,400},
    							{0.33 ,200},
    							{0.25 ,300},
    							{0.15 ,300}};
    i know C99 supports variable sized arrays. so why am i getting this error??

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,437
    Perhaps you forgot to enable C99 support?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    No, I don't think that is the trouble - it seems that the GCC devs are moving toward C99 being the default behaviour. At any rate, if you do not use the std=c99 switch, but have some C99 constructs, it will not complain.

    Perhaps the OP can post a little more code. It seems to me that this has to do with the array being initialised within a function.

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    1,198
    No, this is because you are trying to initialize the array on the same line as you create it.

    This will error:
    Code:
    int someArray[someVariable] = {2,3,4};
    This wont error
    Code:
    int someArray[someVariable];
    someArray[0] = 2;
    // And so on

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c99
    By Nextstopearth in forum C Programming
    Replies: 8
    Last Post: 02-20-2009, 10:58 PM
  2. C89 or C99
    By talin in forum C Programming
    Replies: 6
    Last Post: 05-26-2008, 12:45 PM
  3. C99 and int main()
    By cwr in forum C Programming
    Replies: 8
    Last Post: 09-19-2005, 06:54 AM
  4. C99 support?
    By Devil Panther in forum C Programming
    Replies: 3
    Last Post: 08-22-2005, 02:07 PM
  5. My first game
    By homeyg in forum Game Programming
    Replies: 20
    Last Post: 12-22-2004, 04:25 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21