Skip to content

Instantly share code, notes, and snippets.

@kaworu
Created July 24, 2014 13:28
Show Gist options
  • Save kaworu/35642f625a6bab1ba635 to your computer and use it in GitHub Desktop.
Save kaworu/35642f625a6bab1ba635 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct s {
char *str;
};
int
main(int argc, char **argv)
{
struct s *x;
size_t len = strlen(argv[0]);
x = malloc(sizeof(struct s) + len + 1);
x->str = (char *)(x + 1);
(void)memcpy(x->str, argv[0], len + 1);
(void)printf("voila: %s\n", x->str);
return (0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment