Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The main issue, which the article covers, is that there's really two different operations you want with copying C strings.

Do you want to copy and truncate, or just copy?

Within that, do you want to manage your own allocation, or do you want that abstracted?

There's too many decision points and tradeoffs to just neatly hide behind a single "one true function" for copying C strings.



Is it bad that for all application uses, I reach for `asprintf`?

As well as reaching for the %ms format for scanf for reading input.

For buffers, I use memcpy and length tracking. Any other approach seems like unnecessary headache. Or maybe modern hardware has spoiled me?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: