2 ms·
> the various C compiler vendors could get together and agree on a set of them, making a "technical report". Yes, they could. But they don't. > Anyhow, what
by lisper 10y ago
> the various C compiler vendors could get together and agree on a set of them, making a "technical report".
Yes, they could. But they don't.
> Anyhow, what other problems?
The lack of a real multi-dimensional array type is probably the biggest problem with regards to the goal of making code run fast. The fact that strings are required to be zero-terminated arrays of signed 8-bit integers is another huge problem. It means that you can't have native unicode strings, and that to create a substring you have to make a copy. The lack of exceptions and automatic memory management means that you need weird calling conventions if you want to return composite types, or if a function can fail. The lack of generics and namespacing means that you need to use weird naming conventions to avoid collisions, and there is a significant cognitive load placed on the programmer to figure out the right operation to use for a particular set of operand types (except for native arithmetic, but that can't be extended to any non-native types).
- WalterBright 10y agoI'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 10y 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 10y 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 10y 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 10y 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 10y 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 10y agoAren't any of those negatively affected by the possibility of aliasing?
- WalterBright 10y agoNone of those I mentioned are, though C has the 'restrict' type modifier to deal with that.