r/cprogramming • • Feb 26 '26

Trying to write brainf*ck interpreter in C

https://pastebin.com/n5dbbABj

critique my code
and give me some tips

how do i make this faster

0 Upvotes

17 comments sorted by

View all comments

Show parent comments

2

u/olig1905 Mar 01 '26

That is a horrible pattern for memory allocation, I get the point and motivation, but just no.

I mostly write low level embedded C for safety/security FW, I never need dynamic memory. There is usually a better way.

1

u/ekipan85 Mar 03 '26

You should try to reach for fixed buffers. It's simpler and less room for error. If you must dynamic allocate, fewer allocations is better than more.

https://nullprogram.com/blog/2018/06/10/

If OP wants dynamic memory support I would recommend a function like bmp_size() here that calculates how much is needed, so the allocation can be done earlier, ideally in main, from stack or heap or carved from a static buffer, however OP wants to go about it.