Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6691517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:45:40+00:00 2026-05-26T05:45:40+00:00

I have a very weird issue whilst initializing a struct with GCC 4.5.3 on

  • 0

I have a very weird issue whilst initializing a struct with GCC 4.5.3 on my x86_64 Linux box.

Code in question:

struct apr_finfo_t info = { 0 };

apr_finfo_t is quite some complex struct. I’ll just say it has 17 complex other members.

struct apr_finfo_t {
    /** Allocates memory and closes lingering handles in the specified pool */
    apr_pool_t *pool;
    /** The bitmask describing valid fields of this apr_finfo_t structure 
     *  including all available 'wanted' fields and potentially more */
    apr_int32_t valid;
    /** The access permissions of the file.  Mimics Unix access rights. */
    apr_fileperms_t protection;
    /** The type of file.  One of APR_REG, APR_DIR, APR_CHR, APR_BLK, APR_PIPE, 
     * APR_LNK or APR_SOCK.  If the type is undetermined, the value is APR_NOFILE.
     * If the type cannot be determined, the value is APR_UNKFILE.
     */
    apr_filetype_e filetype;
    /** The user id that owns the file */
    apr_uid_t user;
    /** The group id that owns the file */
    apr_gid_t group;
    /** The inode of the file. */
    apr_ino_t inode;
    /** The id of the device the file is on. */
    apr_dev_t device;
    /** The number of hard links to the file. */
    apr_int32_t nlink;
    /** The size of the file */
    apr_off_t size;
    /** The storage size consumed by the file */
    apr_off_t csize;
    /** The time the file was last accessed */
    apr_time_t atime;
    /** The time the file was last modified */
    apr_time_t mtime;
    /** The time the file was created, or the inode was last changed */
    apr_time_t ctime;
    /** The pathname of the file (possibly unrooted) */
    const char *fname;
    /** The file's name (no path) in filesystem case */
    const char *name;
    /** The file's handle, if accessed (can be submitted to apr_duphandle) */
    struct apr_file_t *filehand;
};

Now, when compiling this piece with GCC 4.5.3 and -std=c99 -pedantic -Wextra, I’m seeing following warning message:

src/switch_apr.c: In function ‘switch_file_exists’:
src/switch_apr.c:518: warning: missing initializer
src/switch_apr.c:518: warning: (near initialization for ‘info.valid’)

Obviously GCC tries to initialize the first member, but already chokes on the second one.
This warning does NOT occur when not building with -W / -Wextra.

I could initialize each member by hand but that sounds weird and wrong.

From what I could gather from a Google search, it seems this initialization is perfectly legit and there are reports for GCC 3 where it works. Not with GCC 4.5 or 4.1 though.

Hope someone can help. 🙂

Best regards,

Mihai

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:45:40+00:00Added an answer on May 26, 2026 at 5:45 am

    The -Wextra command-line option includes the -Wmissing-field-initializers.
    Try adding -Wno-missing-field-initializers to your command-line.

    $ cat 7724939.c 
    #include <stdlib.h>
    
    struct whatever {
      int a;
      int j;
      int k;
    };
    
    int main(void) {
      struct whatever x = {0};
      if (x.k) return EXIT_FAILURE;
      return 0;
    }
    $ gcc --version
    gcc (Debian 4.6.1-4) 4.6.1
    Copyright (C) 2011 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    
    $ gcc -std=c99 -pedantic 7724939.c 
    $ gcc -std=c99 -pedantic -Wall -Wextra 7724939.c 
    7724939.c: In function ‘main’:
    7724939.c:10:10: warning: missing initializer [-Wmissing-field-initializers]
    7724939.c:10:10: warning: (near initialization for ‘x.j’) [-Wmissing-field-initializers]
    $ gcc -std=c99 -pedantic -Wall -Wextra -Wno-missing-field-initializers 7724939.c 
    $ 
    

    Note that the warning is not required by the C Standard. It’s just your compiler trying to be (too) helpful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen some very weird for loops when reading other people's code. I
This is very weird. I have the following code: Assert.AreEqual(new DateTime(2000, 1, 1), DateTime.ParseExact(2000,
I have a rather weird issue. I have an array of html-code in string-format
Im having a very weird issue. I have a normal ajax call that upload
I have a very weird issue with Firefox only (works fine with IE &
I have a very weird issue with fragments. I use the newest support library.
I have a very weird issue. I have a UserControl that has some controls
It is very weird, and I don't have any idea what is the issue!
So I have a very weird problem. I am writing some code in VB.Net
I have a very weird problem: sometimes when I call nHibernate update to an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.