Mercurial
view playground/main.c @ 86:431df06b1a9b
Fixed few things.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Thu, 01 Jan 2026 14:05:34 -0800 |
| parents | 75de5903355c |
| children | f07abbcd2ec5 |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> typedef struct { float foo; float bar; } Values; int capacity = 20; int main() { int a; void *p = malloc(sizeof(Values) + (sizeof(int) * 20)); int *b = (int *)(p + sizeof(Values)); Values *c = (Values *)p; c->foo = 10.0f; c->bar = 12.0f; for (int i = 0; i < 20; i++) b[i] = i; for (int i = 0; i < 20; i++) printf("values is %i\n", b[i]); printf("c->foo: %f\n", c->foo); printf("c->bar: %f\n", c->bar); Values *d = (Values *)b - 1; printf("d->foo: %f\n", d->foo); printf("d->bar: %f\n", d->bar); return 0; }