Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
?!
You can absolutely have mutable strings on the stack.
char buf[11];
would work just fine for both your solutions.Seems like you got pointers and arrays confused. A pointer to a string literal (stored in the data segment) is not a "stack-allocated string". There's a significant difference between
const char *foo = "bar";
andchar foo[] = "bar";
.VLAs don't particularly factor into this, but they are absolutely mutable (seeing as they cannot be initialized, they would be useless otherwise). There is no such thing as "could" when dealing with well defined behaviours.
I think that making it static would not be a good idea.
Putting the string on the heap is important since we need writable memory. If you were to use so-called VLAs (e.g., a string allocated on the stack you could get non-writable memory). In C stack-allocated strings should be considered immutable.
Thus, going with malloc/calloc is a good idea here. Also freeing usually is implemented to be almost constant time, so there's no need to worry about that.
I hope I didn't misunderstand what you meant by static :'D
I've been doing garbage collected languages too much. I'd probably make it static rather than just adding a free for performance.
I personally have no idea of what you mean, please alaborate and I'll include it in the description
Just! I didn't pay attention. Thanks