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

  • Home
  • SEARCH
  • 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 8819449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:21:42+00:00 2026-06-14T05:21:42+00:00

Reading this Skip List implementation I came across this code fragment: typedef struct nodeStructure{

  • 0

Reading this Skip List implementation I came across this code fragment:

typedef struct nodeStructure{
    keyType key;
    valueType value;
    node forward[1]; /* variable sized array of forward pointers */
    };

To me it seems that forward[1] denotes a one element array. And the comment calls it a variable sized array.

Do I misunderstand something or this is just a mistake in the source I’m reading?

  • 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-14T05:21:44+00:00Added an answer on June 14, 2026 at 5:21 am

    This is a common trick for the older C compilers (before C99): compilers allowed you to dereference elements past the end of forward‘s declared length when it is the last element of the struct; you could then malloc enough memory for the additional node elements, like this:

    nodeStructure *ptr = malloc(sizeof(nodeStructure)+4*sizeof(node));
    for (int i = 0 ; i != 5 ; i++) { // The fifth element is part of the struct
        ptr->forward[i] = ...
    }
    free(ptr);
    

    The trick lets you embed arrays of variable size in a structure without a separate dynamic allocation. An alternative solution would be to declare node *forward, but then you’d need to malloc and free it separately from the nodeStructure, unnecessarily doubling the number of mallocs and potentially increasing memory fragmentation:

    Here is how the above fragment would look without the hack:

    typedef struct nodeStructure{
        keyType key;
        valueType value;
        node *forward;
    };
    
    nodeStructure *ptr = malloc(sizeof(nodeStructure));
    ptr->forward = malloc(5*sizeof(node));
    for (int i = 0 ; i != 5 ; i++) {
        ptr->forward[i] = ...
    }
    free(ptr->forward);
    free(ptr);
    

    EDIT (in response to comments by Adam Rosenfield): C99 lets you define arrays with no size, like this: node forward[]; This is called flexible array member, it is defined in the section 6.7.2.1.16 of the C99 standard.

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

Sidebar

Related Questions

I've been reading up on this whole subject, but I never came across this
After reading this: http://docs.djangoproject.com/en/dev/ref/contrib/csrf/#how-to-use-it I came to the conclusion that it is not valid
(can skip this part just an explanation of the code below. my problems are
Reading this DZone article about Java concurrency I was wondering if the following code:
I was reading a wikipedia article on Trimming and saw this implementation of ltrim
Reading this page , it says: ...the URI in a PUT request identifies the
Reading this article http://support.microsoft.com/kb/813878 I have a question: Where can I get ipseccmd.exe for
While reading this class BitmapFactory I noticed that almost all methods inside are static.
After reading this question, I need to clear up some things. IQueryable<Customer> custs =
After reading this article, it makes sense to rebase to gather changes from the

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.