Questions tagged [c]

The C programming language: its historical aspects and use on/targetting retro platforms.

This tag is for questions about the history of the C language and its use on retrocomputers, including C compilers targeting retro platforms.

C programming questions are on-topic only so far as they are specific to a retro platform, such as when asking about platform-specific compiler extensions. General questions about C programming (i.e. those that could apply to modern platforms as well) should be instead asked on Stack Overflow. In particular, this tag is not for versions of C (such as C99) that are not being compiled for retrocomputers (such as code produced by Visual Studio 2013), despite the age of the standard.

98 questions
44
votes
7 answers

The history of the NULL pointer

As we know, in C to dereference a null pointer is undefined behaviour. From what I understand, the PDP-7 and the PDP-11 both have ordinary memory that can be written to and read from at address 0. On the PDP-11, that address is part of a memory…
Omar and Lorraine
  • 38,883
  • 14
  • 134
  • 274
37
votes
6 answers

Why is this gcd implementation from the 80s so complicated?

First of all, I hope this is the right place to post this question. I was looking through one of my dad's old programming books from the 80s, and at the back it has a list of utility functions, one of which is gcd. Its implementation is as…
Calvin Godfrey
  • 473
  • 4
  • 6
33
votes
6 answers

In the ISO 1990 C standard library, what was the rationale for having memcpy return one of its inputs?

The function memcpy is defined as: void* memcpy(void* s1, void* s2, size_t n) and the 1990 ISO standard (ISO 9899:1990) defines the function as: Description The memcpy function copies n characters from the object pointed to by s2 into the object…
Michael Stachowsky
  • 3,151
  • 2
  • 22
  • 31
29
votes
10 answers

Was there any technological reason that C was designed to return only a single thing from a function?

I'm asking specifically about C, not about other contemporary languages, but if the reason is "that's how B did it" or something please assume I'm talking about "in the lineage of C". I'm also aware that many if not all languages also adhere to the…
Michael Stachowsky
  • 3,151
  • 2
  • 22
  • 31
18
votes
1 answer

In P.J. Plauger's "The Standard C Library" (1992), why are for loops used so frequently instead of while loops in the implementations?

I think I'm getting into such a specific question that there may be no answer, but it seems curious to me. This is a retrocomputing question, I promise, see the last paragraph to see how. In Plauger's 1992 book, "The Standard C Library", Plauger…
Michael Stachowsky
  • 3,151
  • 2
  • 22
  • 31
15
votes
2 answers

Has the “entry” keyword ever been implemented in C?

I posted this question on StackOverflow, but someone commented and advised me to publish it here. Here the terms K&R1 and K&R2 refer to a book written by the C creators about the language. K&R1 is the first edition (1978, before the…
Chi_Iroh
  • 253
  • 6
1
vote
2 answers

DOS, create pipe for stdin/stdout of command.com(or 4dos.com) in C or Batch?

I'm working on a retro project and was trying to create a pipe of stdin/out/err in DOS, but I can't find any functions to to this? For instance the pipe() command from unistd.h isn't present in BorlandC, which I'm using. Can anyone tell me how to to…
Dacobi
  • 285
  • 2
  • 6
-2
votes
2 answers

1980s version of printf in C

In a well-known article by Ken Thompson, ( http://users.ece.cmu.edu/~ganger/712.fall02/papers/p761-thompson.pdf ) in figure 1, that formats printf with decimal %d printf("\t%d, \n", s[i]); Why would that be done? Shouldn't it have been %c with…
Niklas Rosencrantz
  • 1,111
  • 8
  • 22