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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:07:25+00:00 2026-06-15T16:07:25+00:00

I need to allocate an array according to how many elements the enum have.

  • 0

I need to allocate an array according to how many elements the enum have. I did the following:

enum { A, B, C, LAST };
char buf[LAST];

That works fine,even with -ansi -pedantic flags. But I’m not sure if it’s a GCC or clang(wich supports most,if not all GCC-extensions) extensions or really allowed by the ANSI C standard and will works fine in any C compiler with ANSI-C std. Can someone clarify it?

  • 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-06-15T16:07:27+00:00Added an answer on June 15, 2026 at 4:07 pm

    Both the C89 (section 3.5.2.2) and C99 (section 6.7.2.2) standards define enums the same way:

    6.7.2.2 Enumeration specifiers (Paragraph 3), http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf

    3.5.2.2 Enumeration specifiers (Paragraph 3), http://flash-gordon.me.uk/ansi.c.txt

    Both read:

    […] An enumerator with = defines its enumeration constant as the value of the constant expression. If the first enumerator has no =,the value of its enumeration constant is 0. Each subsequent enumerator with no = defines its enumeration constant as the value of the constant expression obtained by adding 1 to the value of the previous enumeration constant. […]

    Therefore, in your syntax, any standard-compliant compiler will run your code correctly.

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

Sidebar

Related Questions

I need to have a dynamic array, so I need to allocate the necessary
If I want to allocate a char array (in C) that is guaranteed to
That's pretty much it. I need to allocate memory and pass it to a
I need an array which I can access from different methods, I have to
I need to allocate memory dynamically for an array of pointers. Let us assume,
I have a class that contains a dynamically allocated array, say class A {
I have a very large array of doubles that I am using a disk-based
I need to allocate a varibale size for SYMBOLs, typedef int SYMBOL I did
I asked about NSAutoreleasePool , and understand that I need explicitly allocate autorelease pool
Just on the following code do I need to allocate memory with new for

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.