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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:39:36+00:00 2026-05-31T07:39:36+00:00

Just curious, what actually happens if I define a zero-length array int array[0]; in

  • 0

Just curious, what actually happens if I define a zero-length array int array[0]; in code? GCC doesn’t complain at all.

Sample Program

#include <stdio.h>

int main() {
    int arr[0];
    return 0;
}

Clarification

I’m actually trying to figure out if zero-length arrays initialised this way, instead of being pointed at like the variable length in Darhazer’s comments, are optimised out or not.

This is because I have to release some code out into the wild, so I’m trying to figure out if I have to handle cases where the SIZE is defined as 0, which happens in some code with a statically defined int array[SIZE];

I was actually surprised that GCC does not complain, which led to my question. From the answers I’ve received, I believe the lack of a warning is largely due to supporting old code which has not been updated with the new [] syntax.

Because I was mainly wondering about the error, I am tagging Lundin’s answer as correct (Nawaz’s was first, but it wasn’t as complete) — the others were pointing out its actual use for tail-padded structures, while relevant, isn’t exactly what I was looking for.

  • 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-31T07:39:38+00:00Added an answer on May 31, 2026 at 7:39 am

    An array cannot have zero size.

    ISO 9899:2011 6.7.6.2:

    If the expression is a constant expression, it shall have a value greater than zero.

    The above text is true both for a plain array (paragraph 1). For a VLA (variable length array), the behavior is undefined if the expression’s value is less than or equal to zero (paragraph 5). This is normative text in the C standard. A compiler is not allowed to implement it differently.

    gcc -std=c99 -pedantic gives a warning for the non-VLA case.

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

Sidebar

Related Questions

Just curious. How does actually the function Sleep() work (declared in windows.h)? Maybe not
Just curious how you would comment this line of code: string customerNm = customerNm.EndsWith(s)
Just curious how many people are actually running 2010 and what's your feedback so
Disclaimer: I'm not actually trying to make one I'm just curious as to how
I'm just curious if any project exists that attempts to group all (or most)
just curious if this will actually run, I modelled it after an example from
Does LINQ and Lambda expressions reduce cyclomatic-complexity? Just curious because CodeRush actually shows a
I'm just curious about how Java actually works when it come to if statements.
Simple issue, actually. Just curious if others recognize the problem and perhaps have a
Just curious here: is it possible to invoke a Windows Blue Screen of Death

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.