Created
October 29, 2014 08:55
-
-
Save hduffddybz/74de7cea50b9d153c693 to your computer and use it in GitHub Desktop.
Write indefinite length struct in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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