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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:05:20+00:00 2026-06-06T21:05:20+00:00

I am wondering why I keep getting error: flexible array member not at end

  • 0

I am wondering why I keep getting error: flexible array member not at end of struct error when I call malloc. I have a struct with a variable length array, and I keep getting this error.

The struct is,

typedef struct {
  size_t N;
  double data[];
  int label[];
} s_col; 

and the call to malloc is,

col = malloc(sizeof(s_col) + lc * (sizeof(double) + sizeof(int)));

Is this the correct call to malloc?

  • 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-06T21:05:20+00:00Added an answer on June 6, 2026 at 9:05 pm

    You can only have one flexible array member in a struct, and it must always be the last member of the struct. In other words, in this case you’ve gone wrong before you call malloc, to the point that there’s really no way to call malloc correctly for this struct.

    To do what you seem to want (arrays of the same number of data and label members), you could consider something like:

    struct my_pair { 
        double data;
        int label;
    };
    
    typedef struct { 
       size_t N;
       struct my_pair data_label[];
    };
    

    Note that this is somewhat different though: instead of an array of doubles followed by an array of ints, it gives you an array of one double followed by one int, then the next double, next int, and so on. Whether this is close enough to the same or not will depend on how you’re using the data (e.g., for passing to an external function that expects a contiguous array, you’ll probably have to do things differently).

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

Sidebar

Related Questions

I was wondering why do I keep getting an error and unable to return
Hi I keep getting this error from the below code, was wondering if anyone
I'm wondering if there is a way to call variable functions with namespaces. Basically
I am trying to set SignalR up, but I keep getting the following error
I keep getting this error for a portion of my code. Traceback (most recent
I'm trying to use the ImageMagick toolkit in Drupal, but keep getting this error:
I keep getting an error that states my String index is out of range
I am wondering if there is any way to keep the indentation with jinja
Just wondering for user permission check, Should you keep the permission in the session
I am wondering how I should structure a FAQ to keep the semantic meaning

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.