Skip to content

Instantly share code, notes, and snippets.

@hduffddybz
Created October 29, 2014 08:55
Show Gist options
  • Save hduffddybz/74de7cea50b9d153c693 to your computer and use it in GitHub Desktop.
Save hduffddybz/74de7cea50b9d153c693 to your computer and use it in GitHub Desktop.
Write indefinite length struct in C
#include <stdio.h>
struct Node
{
int data;
int length;
char buffer[0];
};
int main()
{
int buffer_len = 100;
struct Node *node = (struct Node *)malloc(sizeof(struct Node) + buffer_len);
node->length = 100;
printf("len of struct:%d\n", sizeof(struct Node));
printf("len of buffer:%d\n", node->length);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment