summaryrefslogtreecommitdiff
path: root/riscv/riscv-probe/examples/alloca
diff options
context:
space:
mode:
authorCarlos Maiolino <[email protected]>2025-07-10 22:18:39 +0200
committerCarlos Maiolino <[email protected]>2025-07-10 22:18:39 +0200
commit8c6fc0c15415b32080a848bbde640e104098cf13 (patch)
tree04a21bd28f9dc82c8e216390d6208ed93b9bcd11 /riscv/riscv-probe/examples/alloca
Initial drop
Add some riscv code Signed-off-by: Carlos Maiolino <[email protected]>
Diffstat (limited to 'riscv/riscv-probe/examples/alloca')
-rw-r--r--riscv/riscv-probe/examples/alloca/main.c17
-rw-r--r--riscv/riscv-probe/examples/alloca/rules.mk1
2 files changed, 18 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]);
+ }
+}
diff --git a/riscv/riscv-probe/examples/alloca/rules.mk b/riscv/riscv-probe/examples/alloca/rules.mk
new file mode 100644
index 0000000..198ef24
--- /dev/null
+++ b/riscv/riscv-probe/examples/alloca/rules.mk
@@ -0,0 +1 @@
+alloca_objs = main.o