What are the major differences between ANSI C and K&R C?

There may be some confusion here about what “K&R C” is. The term refers to the language as documented in the first edition of “The C Programming Language.” Roughly speaking: the input language of the Bell Labs C compiler circa 1978. Kernighan and Ritchie were involved in the ANSI standardization process. The “ANSI C” dialect … Read more

How to generate NaN, -Infinity and +Infinity in ANSI C?

There is in C99, but not in previous standards AFAIK. In C99, you’ll have NAN and INFINITY macros. From “Mathematics <math.h>“ (§7.12) section The macro INFINITY expands to a constant expression of type float representing positive or unsigned infinity, if available; … If you’re stuck with ANSI C89, you’re out of luck. See C-FAQ 14.9.

Where can one find the C89/C90 standards in PDF format?

You can find nice HTML versions of C89, C99, and C11, as well as some of the official draft PDF files they’re generated from, here: http://port70.net/~nsz/c/ Some other useful direct links to free PDF files of the C89/C90, C99 and C11 standards are listed below: C89/C90: https://www.pdf-archive.com/2014/10/02/ansi-iso-9899-1990-1/ansi-iso-9899-1990-1.pdf C99: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf C11: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf

Why should you use strncpy instead of strcpy?

The strncpy() function was designed with a very particular problem in mind: manipulating strings stored in the manner of original UNIX directory entries. These used a short fixed-sized array (14 bytes), and a nul-terminator was only used if the filename was shorter than the array. That’s what’s behind the two oddities of strncpy(): It doesn’t … Read more