-
-
Save anonymous/b195945385da432773cf to your computer and use it in GitHub Desktop.
This file contains 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> | |
#include <stdlib.h> | |
#include <string.h> | |
int allocate_struct(void *pv, | |
size_t s) | |
{ | |
struct generic *pgs; | |
if ((pgs = malloc(s)) == NULL) { | |
fputs("Error: malloc();\n", stderr); | |
return -1; | |
} | |
memcpy(pv, &pgs, sizeof pgs); | |
return 0; | |
} | |
int main(void) | |
{ | |
struct s1 { int i; } *s1; | |
if (allocate_struct(&s1, sizeof *s1) != 0) | |
return EXIT_FAILURE; | |
s1->i = 123; | |
free(s1); | |
return EXIT_SUCCESS; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment