Thread: warning: excess elements in struct initializer

  1. #1
    Registered User
    Join Date
    Nov 2008
    Location
    Santa Catarina - Brasil
    Posts
    184

    warning: excess elements in struct initializer

    Code:
    struct httpd_fsdata_file {
      const struct httpd_fsdata_file *next;
      const char *name;
      const char *data;
      const int len;
    #ifdef HTTPD_FS_STATISTICS
    #if HTTPD_FS_STATISTICS == 1
      u16_t count;
    #endif /* HTTPD_FS_STATISTICS */
    #endif /* HTTPD_FS_STATISTICS */
    };
    Code:
    const struct httpd_fsdata_file file_404_html = {&file_processes_shtml, (char const*)data_404_html, (char const*)data_404_html + 10, sizeof(data_404_html) - 10};
    
    const struct httpd_fsdata_file file_files_shtml = {&file_404_html, (char const*)data_files_shtml, (char const*)data_files_shtml + 13, sizeof(data_files_shtml) - 13};
    Code:
    httpd-fsdata.c:610: error: variable ‘file_404_html’ has initializer but incomplete type
    httpd-fsdata.c:611: error: unknown field ‘next’ specified in initializer
    httpd-fsdata.c:611: warning: excess elements in struct initializer
    httpd-fsdata.c:611: warning: (near initialization for ‘file_404_html’)

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Ok... is there a question in there someplace?

  3. #3
    Registered User
    Join Date
    Nov 2008
    Location
    Santa Catarina - Brasil
    Posts
    184
    Quote Originally Posted by CommonTater View Post
    Ok... is there a question in there someplace?
    This errors is showed:

    httpd-fsdata.c:610: error: variable ‘file_404_html’ has initializer but incomplete type
    httpd-fsdata.c:611: error: unknown field ‘next’ specified in initializer
    httpd-fsdata.c:611: warning: excess elements in struct initializer
    httpd-fsdata.c:611: warning: (near initialization for ‘file_404_html’)

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Ok.... is there a question in there someplace?

  5. #5
    Registered User
    Join Date
    Nov 2008
    Location
    Santa Catarina - Brasil
    Posts
    184
    Quote Originally Posted by CommonTater View Post
    Ok.... is there a question in there someplace?
    What's wrong in this code to show this errors during compilation?

    (Sorry for my english)

  6. #6
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,907
    It's hard to say without seeing all the code. It sounds to me like perhaps the definition of the struct is not visible when you define and initialize file_404_html, so the compiler doesn't know what it should look like and whether you're initializing it correctly. This might have to do with the struct being in a different file and not being #included, or with the order of the statements in your code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Constructor Initializer List Problem (New (to me) compiler warning)
    By M.Richard Tober in forum C++ Programming
    Replies: 2
    Last Post: 10-24-2011, 01:47 AM
  2. Warning: excess elements in scalar initializer
    By TeRMaL in forum C Programming
    Replies: 9
    Last Post: 10-08-2010, 03:54 AM
  3. warning: excess elements in array initializer
    By redruby147 in forum C Programming
    Replies: 6
    Last Post: 09-30-2009, 06:08 AM
  4. Replies: 10
    Last Post: 08-27-2009, 09:58 AM
  5. Replies: 12
    Last Post: 01-17-2009, 04:35 AM