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

Mostly reasonably written article, but the string handling bit was slightly off imho.

> Of course, the comparatively easy string handling in high-level languages will really be having to do all of this same work; it's just that the language hides it from you, and takes care of the tedious details automatically

No, not really. Good string type would reduce the workload down to the hardware. Eg length-prefix strings would avoid the slow strlens for concatenation.

Also imho the horror of undefined behavior should have been underlined even more, eg:

> So C will typically let you just construct any pointer value you like by casting an integer to a pointer type, or by taking an existing pointer to one type and casting it so that it becomes a pointer to an entirely different type.

Afaik both of those are undefined behavior, so it is questionable to say that C "lets" you do that.



>Eg length-prefix strings would avoid the slow strlens for concatenation.

But this would be suboptimal in other ways. Besides taking more RAM, it would get in the way of useful tricks like "temporarily shorten string by setting a particular byte in it to \0", or even more useful, "obtain right-terminal substring by simply increasing pointer value".

Different string implementations are more efficient in different scenarios. I love how C gives us standard libraries for a particular string implementation (NULL-terminated) but at the same time allows the flexibility to use whatever implementation we like, by not abstracting all the details out of our control.


>by casting an integer to a pointer type That's implementation-defined. The opposite too except if the result can't be represented in the integer type.

>by taking an existing pointer to one type and casting it so that it becomes a pointer to an entirely different type. It isn't that easy, but it's well-defined as long as both pointers are compatible and identically qualified.




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

Search: