Hot answers tagged

72

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 ...


70

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 ...


65

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 ...


60

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 ...


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 ...


57

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.  ...


55

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-...


55

The C standard of the language doesn't mandate a 32-bit int. It defines sizeof(char) = 1 and sizeof(long long) ≥ sizeof(long) ≥ sizeof(int) ≥ sizeof(short) ≥ sizeof(char) It also mandates that the constant in limits.h are at least the values given below #define CHAR_BIT 8 #define CHAR_MAX UCHAR_MAX or SCHAR_MAX #define CHAR_MIN 0 or SCHAR_MIN #define INT_MAX ...


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

For type system reasons, and for compatibility with B. B is a programming language that served as the immediate ancestor of C. The salient thing about B is that it had no type system: all values in B are machine words (corresponding to the C type int). In B, there were two ways to represent strings in source code: string literals0, which evaluated to a ...


46

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 ...


45

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 ...


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 ...


42

It was a pointer arithmetic hack, later abstracted away into a more portable form in some version of Unix; even later, it was adapted into ANSI C. In many languages (like Pascal for example), variadic functions, if they were included at all, had to be handled as special cases. B, which was the predecessor to C, did not have to, because B did not require ...


41

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 ...


38

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 ...


38

This is (or at least appears to be) the binary euclidean GCD. https://en.wikipedia.org/wiki/Binary_GCD_algorithm has a slighty different version (but the version you post has the nice feature that there's no recursion (which I seem to recall earlier C compilers wanted to limit). As I noted in my comment that I deleted when I realized I do have access to ...


37

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 ...


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

The requirement that argv[argc] be NULL was added in 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 was kept thereafter ...


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 ...


34

In V6, the C preprocessor is part of cc, the compiler driver; see the expand() function in cc.c. The directory you linked to contains the source code to the two passes of the C compiler, c0 and c1 (and their floating-point variants, fc0 and fc1), and the optional optimiser, c2. The passes are driven by cc, whose source code is available in the s1 directory. ...


32

You get SIGPIPE only if you try to write to a pipe that has no readers anymore. The idea is that typical unix processes run to produce output. If the output is going to a pipe, but no one is reading from a pipe, the process got useless and may be killed. You never get SIGPIPE reading from an input pipe. If you read from an input pipe that has no writers ...


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 ...


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