diff options
Diffstat (limited to 'riscv/riscv-probe/examples/alloca/main.c')
| -rw-r--r-- | riscv/riscv-probe/examples/alloca/main.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/riscv/riscv-probe/examples/alloca/main.c b/riscv/riscv-probe/examples/alloca/main.c new file mode 100644 index 0000000..af9696a --- /dev/null +++ b/riscv/riscv-probe/examples/alloca/main.c @@ -0,0 +1,17 @@ +#include <stdio.h> +#include <alloca.h> +#include <string.h> + +int main(int argc, char **argv) +{ + const size_t nelems = 4; + const size_t elemsize = 128; + char *alloc[nelems]; + + for (size_t i = 0; i < nelems; i++) { + if (alloc[i] = alloca(elemsize)) { + memset(alloc[i], 0, elemsize); + } + printf("alloca[%d]=0x%x\n", i, alloc[i]); + } +} |
