Hot answers tagged

68

Dennis Ritchie’s paper on The Development of the C Language gives some idea of the reasoning behind this: namely, the fundamental rule in C that declaration syntax should match expression syntax. For each object of such a composed type, there was already a way to mention the underlying object: index the array, call the function, use the indirection operator ...


61

In the embryonic form of C described in the 1974 C Reference Manual, there was no requirement that the left operand of . actually be a structure, nor that the left operand of -> actually be a pointer. The -> operator meant "interpret the value of the left operand as a pointer, add the offset associated with the indicated structure member name, and ...


57

Simply yes. And not just a few instructions, but whole CPUs have been developed with languages in mind. Most prominent maybe Intel's 8086. Already the basic CPU was designed to support the way high level languages handle memory management, especially stack allocation and usage. With BP a separate register for stack frames and addressing was added in ...


55

If you try translating C into Z80, you'll see that Z80 index registers and stack don't behave quite as you expect. So, let us begin with Arrays Suppose you have a standard C construction int c[10]; for (int i=0; i<10; i++) c[i]=0; Your compiler is pretty much required to use 16-bit value for i. So, you have &c somewhere, maybe even in your ...


52

The main downside of "historic" CPU's (non?)-suitability for C programs is the lack of capability to form more than one register into an address without using the ALU. Most more modern CPUs can use base + index + offset register addressing modes to address complex data structures like arrays and structures - The Z80 needs to painstakingly go through the 4-...


52

Quite often people don't know how to use the compilers or don't understand fully the consequences of code they write. There is optimization going on in the z80 c compilers but it's not as complete as, say, gcc. And I often see people fail to turn up the optimization when they compile. There is an example here in introspec's post that I am not allowed to ...


48

Interesting question with an interesting answer. First let me get one thing out of the way: One example from this answer mentions how C pointers were, at least in part, influenced by the design of the PDP-11 It's a myth to suggest C's design is based on the PDP-11. People often quote, for example, the increment and decrement operators because they have ...


48

Some of the first C code I saw was like this: 0x8040->output = 'A'; — its purpose was accessing memory mapped I/O locations.  Needless to say it took me a while to figure out what this code was supposed to do, and the hex constant there really threw me. The original K&R C placed all field names (here output) into the same namespace.  ...


47

No, it didn't. MS-DOS never bothered to zero out allocated memory, as there was no security reason to do so like there is in a multi-user operating system. It was up to the C runtime startup code to zero out the BSS segment. For example, from the Borland C++ 3.1 startup code: ; Reset uninitialized data area xor ax, ax ...


44

One interesting example of programming languages driving hardware development is the LISP machine. Since "normal" computers of the time period couldn't execute lisp code efficiently, and there was a high demand for the language in academia and research, dedicated hardware was built with the sole purpose of executing lisp code. Although lisp machines were ...


43

So you want to write a C program for the IBM PC before the first C compiler for the PC is released. How do you go about it? There are three options I can see: Write your own C compiler Use a cross compiler for 8086 on some other platform Wait for a C compiler to become available Don't use C No four options. Amongst our many options are fear, surprise and ...


43

C didn't spring into being suddenly, but was created by slowly modifying the B language--which was written in itself. Therefore you might say that C was always written in itself, but at first it was just a slightly modified B. Dennis Ritchie describes the evolution of C in The Development of the C Language. He started by making small improvements to the B ...


42

Word size is not really an issue in implementing C on a given architecture. There's no requirement that C types have a power-of-two size. There's only a problem if the word size is too small, but this can be simply worked around by using multiple consecutive words to represent C types like int and long. There's a long list of C compiler implementations for 8-...


39

K&R first edition (1978) does not mention the NULL terminator in the argv list at all. This was added later, in ANSI C. The relevant paragraph (section 5.11, p. 110) is: In environments that support C, there is a way to pass command-line arguments or parameters to a program when it begins executing. When main is called to begin execution, it is called ...


39

Despite your assertion, there would in fact be situations where it would be ambigious. First off, early C compilers were very simple. This was in fact the main appeal of the language, as compilers for it were very easy to create and could run on very small systems, like early 16/32 microprocessors. Adding a bunch of code for hitting all the niche cases of ...


37

Was Ritchie correct, or was he just being modest? I’m not sure modesty plays a part here; I don’t see any statement of value attached to the size of a language’s family. As of the date of the quote (1993), were more computer languages descended from Pascal than C? Yes, he was correct, at least as phrased in the paper. Perceptions are perhaps biased ...


36

Simple answers one easily gets to this question are The Z80 Sucks and C Sucks - depending on the side someone is on. While they are of course, untrue (*1), there are real issues. A major argument for both sides is that C is at core tied to a PDP-11(ish) CPU architecture and the Z80 isn't one. The Z80 is a rather special CPU, created with a focus on maxing ...


36

The architecture of the original IBM PC (and its clones) let the BIOS access the video memory directly. So making nice text layouts did not require positioning the cursor or making a sequence of calls like you would do with curses: It was sufficient to set the text mode at startup and write at the right place in memory the character (1 byte) and its ...


35

The Early Days As you said, the most important languages on the Mac in its early days were Microsoft's BASIC, Pascal, and, of course, 68000 assembly. The Macintosh's System Software and ROMs were themselves programmed largely in assembly, with a bit of Pascal thrown in (mostly for pieces that were ported directly from the Lisa). C was merely a niche language ...


31

One option might have been using “Small C,” which was published in 1980 in Dr. Dobb's Journal magazine. Initially it generated code for the 8080, but was adapted for a few other CPU's. It was adapted to generate code for DOS/8088 but I do not know the date. Small C was written in itself so you would need a CP/M-80 system to do the port. But if I recall ...


31

The team working on Unix at the time considered the PDP-7 to be obsolete, and had no interest in making Unix into a finished system to run on it; they only used it originally because the machine was available to them and they had little other use for it. Plus, Bell had little interest in developing operating systems per se, and only financed development of ...


30

The BDS C compiler was released in 1979, ran on CP/M, and was capable of generating code for the Intel 8080 microprocessor. (It also ran on and generated code for the Zilog Z80, but that's not relevant here). This was a very popular, well-known CP/M compiler, and as Wikipedia says: It ran much faster and was more convenient to use than other Z80-hosted ...


30

TUI-drawing code can be pretty compact when you're working in assembly and relying on the IBM video BIOS to do the heavy lifting. For example: INT 10h/AH=06h and INT 10h/AH=07h can be used either to scroll a rectangular region of the screen or to clear the screen to a specified foreground/background colour combination. INT 10h/AH=09h can be used to tile a ...


29

The PDP-7 was too small and too slow; quoting Dennis M. Ritchie in The Development of the C Language: On the PDP-7 Unix system, only a few things were written in B except B itself, because the machine was too small and too slow to do more than experiment; rewriting the operating system and the utilities wholly into B was too expensive a step to seem ...


27

The requirement that argv[argc] be null was added in the first version of the ANSI C standard; it wasn’t a requirement before then, and some environments didn’t null-terminate the array (the strings themselves were of course null-terminated). In fact, in Unix V4, argv[argc] was documented as being -1 and not 0. Thus before ANSI C, argc was necessary, and it ...


27

The definition of NULL is a syntactic crutch to allow a programmer a clear expression that a pointer is, at certain times, pointing nowhere. It's meant for readability - and with increased compiler bloat even for automated checks. On a hardware level there is no such thing. A pointer is a word, and a word always holds a valid number. So by convention zero ...


27

I think it’s worth looking at the rise of Turbo Pascal (in particular) to understand its “downfall”. When Turbo Pascal was released, it has a number of advantages over the competition, regardless of programming language: it was fast, it produced (reasonably) fast programs, it came with excellent documentation, it included a full development environment with ...


23

The first compiler for PC-DOS was Lattice C, released in June, 1982. This compiler was also distributed under license as Microsoft C v2.0. The Lattice C compiler was very popular and widely ported, available on several 1980s retrocomputers including Amiga, Atari ST, and Sinclair QL. The Lattice compiler was acquired by SAS Institute in 1987 and renamed SAS/C....


22

If you want it contemporary, use HiSoft C. Back then the standard compiler and compatible with other HiSoft Tools. For a more up to date and rather comfortable (cross) compiler Z88dk with its Spectrum target might be a good choice. The detailed documentation is a great plus.


21

Yes. Case in point, the VAX. The instruction set design was influenced by the requirements of the compiled languages of the day. For example, the orthogonality of the ISA; the provision of instructions that map to language constructs such as 'case' statements (in the numbered-case sense of Hoare's original formulation, not the labelled-case of C), loop ...


Only top voted, non community-wiki answers of a minimum length are eligible