Hacker News new | ask | show | jobs
by PaulHoule 1559 days ago
Well, many people don’t want to pay the factor of 2 performance cost of a managed language like Java and strcpy in C is Turing complete and most code has to portable to at least x86 and ARM (often both 32 and 64 bits) so assembly is out…
2 comments

> 2 performance cost of a managed language like Java

It can be a lot worse too. Java lacks the ability to have really compact data structures and can not lean in too much into the hardware acceleration without becoming incompatible. You can't exactly set `--fast-math`. Shame GCJ got dropped.

> strcpy in C is Turing complete

Not something I've heard of - is this an abuse of Unicode?

> most code has to portable to at least x86 and ARM (often both 32 and 64 bits) so assembly is out…

(I've not looked into this deeply) - It should in theory be possible to offer translation from one architecture to another, but I guess it is much more effort than it is worth.

Seems like if you could translate your assembly into LLVM equivalent assembly (or just use it directly), you could then build for the target architecture [1].

[1] https://stackoverflow.com/questions/7773194/is-it-possible-t...

> strcpy in C is Turing complete

Maybe GP meant printf [0]?

[0] https://www.ioccc.org/2020/carlini/index.html

> strcpy in C is Turing complete

I was curious too, but my google-fu did not succeed. The closest I found is about printf being Turing-complete [1], which is also new to me.

[1] https://www.ioccc.org/2020/carlini/index.html

It’s not the strcpy that’s Turing complete, it’s the return afterwards… this is not true about PASCAL and many other programming languages.
> strcpy in C is Turing complete

How so? You've made this claim twice (https://news.ycombinator.com/item?id=27910640), but I can find nothing else to back this up. We know about C++ templates "accidentally" being discovered to be Turing complete, but I've never heard of strcpy() being so...

    while((*p++=*q++));
... I'm not seeing it.

Honest question, can you shed light on how this can be?

Strcpy is a good setup for a buffer overflow despite having to run a gauntlet of countermeasures to really pull it off in 2022.
Well, OK, but that isn't fair to say "C" or strcpy(). That's the implementation - so is it surprising that the common underlying implementation of "C" can be coerced into indeterminate or even Turing complete behavior?

It's fair to say that C allows unsafe calls. It's useless to point out that undefined-behavior and unsafe calls could result in Turing completeness. Strcpy() is not Turing complete - it doesn't automatically detect and protect against unsafe usages. That are evil.