4 ms·
I don’t see what makes htons special here. The C standard library is full of functions that return an int that isn’t an integer. For example, printf returns “a
by Someone 3y ago
I don’t see what makes htons special here. The C standard library is full of functions that return an int that isn’t an integer.
For example, printf returns “a nonnegative integer or an error code”, creat returns a file descriptor, mknod returns a Boolean (coded as 0=true, -1=false) and sets errno, but all have return type int.
Strong typing historically wasn’t a goal at all in C. K&R C and its predecessors liked everything to be an int, where possible. For example, if your code called a function foo, the compiler assumed it would be able to find it at link time and return an integer (the ‘implicit int rule’)
- selimthegrim 3y agoThis is why the old Borland Turbo C always had you define bool at the beginning. It was also cool with void main(void) but that’s another story.
- Someone 3y agoEveryone can be cool with void main(void) nowadays in C. https://en.cppreference.com/w/c/language/main_function https://en.cppreference.com/w/c/language/main_function: “Every C program coded to run in a hosted execution environment contains the definition (not the prototype) of a function named main, which is the designated start of the program. int main (void) { body } (1) int main (int argc, char *argv[]) { body } (2) /* another implementation-defined signature */ (since C99.) (3) ” (C++ is a bit more strict. There, main must return an int)