3 ms·
I'm aware of C's language problems, but I don't think the ones you mention impede encapsulation of algorithms so the compiler can do a better optimization job.
by WalterBright 11y ago
I'm aware of C's language problems, but I don't think the ones you mention impede encapsulation of algorithms so the compiler can do a better optimization job.
> strings are required to be zero-terminated arrays of signed 8-bit integers
This is incorrect. C's char type is optionally signed, not required to be signed. The implementations I know of make them unsigned, because signed characters make no sense.
- lisper 11y ago> I don't think the ones you mention impede encapsulation of algorithms so the compiler can do a better optimization job. Unless you can produce an actual counter-argument I guess we'll just have to agree to disagree about that. > signed characters make no sense I could not agree more. And yet... [ron@mighty:~] gcc -v Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn) Target: x86_64-apple-darwin13.4.0 Thread model: posix [ron@mighty:~] cat test.c int main(int argc, char** argv) { unsigned char* x = "baz"; } [ron@mighty:~] gcc test.c test.c:3:18: warning: initializing 'unsigned char *' with an expression of type 'char [4]' converts between pointers to integer types with different sign [-Wpointer-sign] unsigned char* x = "baz"; ^ ~~~~~ 1 warning generated.
- WalterBright 11y agoDang, you're right. D's chars are unsigned, and I had gotten so used to that I forgot that C compilers often default to signed. Thanks for the correction.
- fanf2 11y agoThe ARM C compiler I used over 20 years ago had unsigned chars. I don't know if that is still true for modern ARM.
- WalterBright 11y ago> Unless you can produce an actual counter-argument There's no problem having a function called popcnt(), and having the C compiler recognize it just like it recognizes memcpy(), strlen(), sqrt(), etc., and generate optimal code for it.
- lisper 11y agoSure, that is not in dispute. What is in dispute is whether the same can be done in C for matrix_multiply (or, even better, m1*m2 where m1 and m2 are matrices) or string.split(string) or strings.join(sequence_of_strings) or dict.get(key) or...
- coldtea 11y agoAren't any of those negatively affected by the possibility of aliasing?
- WalterBright 11y agoNone of those I mentioned are, though C has the 'restrict' type modifier to deal with that.