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

In C, unlike pretty much every other language, you can't even know how big an integer is.


Of course you can, but this is implementation defined. So you need to create code that does different things based on the underlying implementation. Every reasonably large C code base checks the current implementation to define what type of integers, pointers, etc. they're dealing with.

This is by design, because C was created do deal with disparate processors and OSs. When it was crated it would be difficult and unwise to assume that an integer has size of 2 bytes, for example, since each machine would define its own preferred length.


> When it was crated it would be difficult and unwise to assume that an integer has size of 2 bytes

It was still a bad design. Of course this is in hindsight, but history has taught is it would have been much better if the default was for specific sized integers, with an option to use `uint_fast32_t` or whatever.


Then we would be stuck with 16 bits integers. We are lucky to be in a point in time where integer types have been stable for a while, but it wasn't always so.


We wouldn't. People would update their code eventually or opt in to variable sized integers.


History says otherwise: C was so successful it is still widely used.


Just because something is popular doesn't mean it's good. Tobacco smoking is also popular.


Some of the best software we have to date was written in C. If you like it or not, it is a magnificent tool.


It would still be good if it was written in a different language. Probably even better because the developers would have more time to improve the software instead of reinventing wheels, writing boilerplate code and chasing down segfaults.


> It would still be good if it was written in a different language.

But it wasn't, C made all these software tools possible.


No it didn't. C happened to be the most popular language for a long time but that doesn't mean people couldn't have written software without it, or that if it hasn't been so popular a better language wouldn't have arisen.

English is very popular but you wouldn't say "English is what made all those books possible" would you?


Yes it did and continues making it possible. Several of the largest codebases in the world are written in C.


To reiterate, C didn't make it possible to write those codebases just because they happen to be written in C.


Yes, it did. Just check how they created UNIX.


Sure you can, it's called sizeof(int). Now read the other comment to understand why.




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

Search: