Re:Once upon a time, memory allocators made sense
by scott_s on Monday January 18, 2016 @11:51AM
(#10925392)
Yeah, but it's cumbersome because you have to define that struct elsewhere, and C does not have elegant mechanisms for destructing in-place.
[ Parent
| on HN ]
Re:Once upon a time, memory allocators made sense
by ratboy666 on Monday January 18, 2016 @03:20PM
(#10926634)
How about
#include <stdio.h>
typedef struct mystruct {
int x;
char *p;
} mystruct;
mystruct func(int n) {
return (mystruct) { n, NULL };
}
int main(void) {
mystruct v = func(1);
printf("%d\n", v.x);
printf("%d\n", func(2).x);
return 0;
}
Works fine with gcc 5.3.1. Multiple destructuring is (maybe) problematic, but if you really want this.