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 7694371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:18:17+00:00 2026-05-31T21:18:17+00:00

In reference to GCC’s Zero Length Array explanation: This is particularly useful in the

  • 0

In reference to GCC’s Zero Length Array explanation:

This is particularly useful in the case when a struct is a header for a variable-length object. This is exactly my case. Furthermore, I am concerned with the alignment of my structs in the heap.

In this case, I still really do not understand what’s useful about zero length arrays. How are they related to this particular situation?

EDIT:

Is it that I can put as much “data” as I want in there?

  • 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-31T21:18:19+00:00Added an answer on May 31, 2026 at 9:18 pm

    Basically it allows you to have a structure with a variable length array at the end:

    struct X {
      int first;
      int rest[0];
    };
    

    An array size of 0 is not actually valid (although it is allowed as a gcc extension). Having an unspecified size is the correct way.
    Since C doesn’t really care that you are accessing elements beyond the end of the array, you just start with an undefined array size, and then allocate enough memory to handle however many elements you actually want:

    struct X *xp = (struct X *)malloc(sizeof(struct X)+10*sizeof(int));
    xp->rest[9] = 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is in reference to a solution posted on: Looping a fixed size array
Now and then when using GCC I get cryptic errors like this: undefined reference
In reference to fastest sort of fixed length 6 int array , I do
In reference to this answer to a Stack Overflow question : what is bench-testing
Object reference not set to an instance of an object. using System; using System.Collections.Generic;
I have linkers errors(undefined reference) that I cannot solve by myself. I use GCC
Why am I getting an undefined reference error using gcc? I am trying to
How do I reference and communciate with an ActiveX library from within my gcc
(This is gcc 3.3.1 (long story -- blame NIST) on Cygwin.) I have compiled
Are there Visual C++ versions of the following (in GCC)? __builtin_return_address __builtin_frame_address Reference -

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.