Questions tagged [c]

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

Filter by
Sorted by
Tagged with
98 votes
9 answers
38k views

Why do C to Z80 compilers produce poor code?

When reading some other questions about compiling C for the Z80, How much benefit should be expected on a more advanced compiler for z80/r800 based computers? Native C compiler for Sinclair ZX ...
user avatar
  • 34.3k
90 votes
20 answers
19k views

Have programming languages driven hardware development?

Programming language development has been influenced by hardware design. One example from this answer mentions how C pointers were, at least in part, influenced by the design of the PDP-11. Has the ...
user avatar
  • 863
72 votes
5 answers
16k views

Why did C use the arrow (->) operator instead of reusing the dot (.) operator?

In the C programming language, the syntax to access the member of a structure is structure.member However, a member of a structure referenced by a pointer is written as pointer->member ...
user avatar
  • 14k
58 votes
4 answers
11k views

Why were single quotes ('…') chosen for characters, and double quotes ("…") for strings?

In C, '' is used to denote a character, while "" is used to denote a string. Why was this syntax chosen? I tried to research this using Wikipedia’s Timeline of Programming Languages along ...
user avatar
  • 633
52 votes
5 answers
16k views

Why did C have the return type before function names?

In general, there are two types of syntax of defining functions - Something like C, C++, C#, or Java (int functionName(char arg)) vs the ML (and others) tradition of defining the return type after the ...
user avatar
  • 1,503
50 votes
2 answers
24k views

Why were the /\ (min) and the \/ (max) operators abandoned in the C language?

In the UNIX V7 version of the C language (but not yet in the V6 version), there were the /\ (min) and the \/ (max) operators. In the source of the scanner part of the compiler, case BSLASH: if (...
user avatar
  • 15.8k
47 votes
3 answers
5k views

How did varargs in C develop?

C has a feature for variadic functions, my understanding is this feature was originally a hack, relying on the simple stack-based parameter passing used by early C implementations and that some time ...
user avatar
  • 1,879
42 votes
7 answers
9k views

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 ...
user avatar
  • 34.3k
40 votes
4 answers
6k views

When was this C function definition style, with type declarations of parameters after the parameter list, invented?

Recently I dug a little bit into old graphics libraries and found libxmi. The site was last updated on 08/09/2000. And in the source code I found the following style of function definitions which I ...
user avatar
  • 583
38 votes
6 answers
7k views

Why couldn't early C compilers handle variable declarations between statements?

In modern C, you may place variable declarations between statements: do_something(); int x; x = something_else(); However, older C compilers required that variables are declared before all statements:...
user avatar
  • 14k
36 votes
5 answers
9k views

Why (historically) include the number of arguments (argc) as a parameter of main?

A comment on this answer to a StackOverflow question made me curious. According the C99 standard, section 5.1.2.2.1: The function called at program startup is named main. The implementation ...
user avatar
  • 653
36 votes
6 answers
5k views

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 ...
user avatar
33 votes
2 answers
5k views

Why was UNIX never backported to the PDP-7?

Originally, UNIX was written in PDP-7 assembly, and then in PDP-11 assembly, but then when UNIX V4 began to be re-written in C in 1973 and was run mostly on the PDP-11. So far as I can tell, there ...
user avatar
  • 34.3k
32 votes
6 answers
6k views

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 ...
user avatar
32 votes
2 answers
8k views

Which tools were used to create the C language?

Was the original C compiler written in some old assembly language and now later flex and bison are used instead?
user avatar
32 votes
3 answers
8k views

Was Dennis Ritchie being too modest in this quote about C and Pascal?

In his 1993 conference proceeding The Development of the C Language, Dennis Ritchie stated Successors C and even B have several direct descendants, though they do not rival Pascal in ...
user avatar
  • 14k
31 votes
5 answers
6k views

How was the C language ported to architectures with non-power-of-2 word sizes?

By the time the C language started to gain popularity outside of the PDP-11 circles (mid-1970s), mainframes with "weird" word sizes, and no capability to address individual bytes efficiently were ...
user avatar
  • 15.8k
31 votes
3 answers
4k views

Why is the ‘auto’ storage class specifier included in C?

The auto keyword in C seems quite redundant: wherever it makes sense to define a variable with automatic storage duration, it is already the default, so there is no reason to use the keyword. The ...
user avatar
  • 16.6k
30 votes
1 answer
3k views

Did DOS zero out the BSS area when it loaded a program?

As an example, say we have a DOS MZ EXE file that's around 20 KiB in size. The EXE header contains the value 0x1400 at offset 0x0A indicating that the program is requesting 5,120 paragraphs (or 80 KiB)...
user avatar
  • 1,441
29 votes
9 answers
10k views

How did early x86 BIOS programmers manage to program full blown TUIs given very few bytes of ROM/EPROM?

I've always wondered how so much functionality and relative luxuries(CMOS Configuration Utilities. See: https://geekprank.com/bios/ for an example) included with most popular x86 BIOSes could be ...
user avatar
28 votes
10 answers
16k views

How to get started writing C for the IBM PC in 1980-81

Suppose it's late 1980 to early 1981, you've got some software you want to write for the IBM PC which will be released later in 1981, want to get started ASAP, and believe C is the right language for ...
user avatar
  • 49.3k
26 votes
9 answers
5k views

How common was programming in C targeting 8-bit processors in 1983?

How often was C used to program firmware for 8-bit processors in the early 80s? I'm reverse engineering a firmware binary for a device built around a Hitachi 6303 processor, manufactured in 1983. Even ...
user avatar
  • 669
26 votes
1 answer
4k views

Where is the ancient preprocessor?

I found the old C compiler from V6, and, though it seems to the modern eye a little different from good, idiomatic C, evidently it uses things like #include and #define, but I do not see how it ...
user avatar
  • 34.3k
24 votes
11 answers
10k views

Why weren't 80s arcade games programmed in C?

I know many arcade games from the 80s were programmed in 68000 assembly. This carried on probably well into the 90s, even though Motorola C compilers existed in the 80s. Why then weren't C compilers ...
user avatar
  • 341
21 votes
2 answers
3k views

What was the first C compiler for the IBM PC?

When did a C compiler first become available for the IBM PC? I have fond memories of Turbo C, but that didn't become available until the mid to late eighties; it definitely wasn't the first one. ...
user avatar
  • 49.3k
20 votes
3 answers
6k views

Native C compiler for Sinclair ZX Spectrum

I am looking for a native C compiler for the Spectrum 128. I would like one which: Has good support for the latest C standard at the time. Is not limited to compiling ridiculously short source code. ...
user avatar
  • 1,780
19 votes
10 answers
7k views

When if ever was the C language 'int' size altered from the host machine word (register) size into a literal 32 bit size?

From the earliest K&R reference manuals I read, 'int' was synonymous with machine word and it seemed to raise adverse reactions in various user domains. With the UNIX crowd, they minimally ...
user avatar
  • 389
19 votes
6 answers
4k views

What caused the downfall of Pascal? [closed]

From 1985 to 1990 Borland's Turbo Pascal was at least as popular as C for DOS systems. Turbo Pascal was especially popular because of it's ground breaking BGI graphics interface while C was stalled in ...
user avatar
  • 4,291
19 votes
0 answers
1k views

Oxford C compiler for Commodore 64

I kept one floppy from my Commodore 128 (which I used mostly in C64 mode), labelled ‘Oxford C compiler’. It is a 5.25″ floppy. Don't ask me why I kept just this one; probably because I thought I ...
user avatar
16 votes
1 answer
3k views

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 ...
user avatar
16 votes
3 answers
1k views

Are there any public tools for the TMS34010?

I am interested to learn about the Texas Instruments TMS34010, a 32-bit fully functional CPU with built-in graphics manipulation capabilities, which appeared in Atari's Hard Drivin' arcade boards ...
user avatar
  • 1,732
15 votes
1 answer
3k views

What was the first C compiler for the Mac?

When did a C compiler first become commercially available for the Apple Macintosh? And what was its name? The only programming languages that I recall were available for the Mac at launch (January ...
user avatar
  • 7,754
15 votes
1 answer
2k views

How would old software using the SIGPIPE signal really work if it were to manage _many_ pipes?

I'm wondering what was the thinking behind having a SIGPIPE signal. From my own experience, the first thing I do is turn off that signal (SIGIGN) and use the return value of the calls to make sure it ...
user avatar
14 votes
2 answers
2k views

How would I reliably detect the amount of RAM, including Fast RAM?

If I was to write an Amiga game, what would be the best/most reliable way to detect how much RAM is actually available? Looking at Action's Guide to AGA-Fixing!, he mentions Faulty Memory Detection: ...
user avatar
  • 525
14 votes
1 answer
2k views

How can I set up the Microsoft C compiler to make it prefer immediate-mode push instructions?

I started a project to get a better understanding on how to compile a game for Windows 3.x. I tried to set up the build workflow so that it produce the byte-exact clone of a great open sourced Win16 ...
user avatar
13 votes
10 answers
2k views

Alternatives for TurboVision on DOS

TurboVision was a library by Borland for developing TUI's (Text User Interfaces). It was included with their C++ and Pascal compilers. Were there any other TUI libraries that supported multiple ...
user avatar
13 votes
3 answers
1k views

Memory models for assembly libraries for Turbo C

Turbo C follows the Intel Memory Model where in Tiny, Small and Compact models calling a function is near but in Medium, Large and Huge models calling a function uses far calls. If I want to develop ...
user avatar
  • 325
11 votes
3 answers
4k views

How can I create a pipe for stdin/stdout of command.com (or 4dos.com) in C or a batch file?

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() function from unistd.h isn't present in ...
user avatar
  • 275
11 votes
3 answers
2k views

Is this the reason why fread/fwrite has 2 `size_t` arguments?

It just came to me that, the C standard I/O functions fread and fwrite are having 2 size_t arguments because of I guess possibly, that on some systems, there may be more memory of which whose size can ...
user avatar
  • 325
11 votes
3 answers
1k views

Are there architectures with alignment greater than the size of machine word in the pre-32-bit era?

I'm writing a hobbyist cryptography project, and I want to ensure the data structures I define don't have padding bytes. The only assumption I've made about the environment, is that bytes are exactly ...
user avatar
  • 325
11 votes
1 answer
837 views

cprintf printing invisible characters in C program on VIC 20

I want to compile and run a Hello World program in C with the cc65 compiler for an unexpanded VIC-20 model. For printing I'm using the conio.h function cprintf, since the conio implementation requires ...
user avatar
  • 4,080
9 votes
2 answers
549 views

Which linker or object-file format imposed the 6-character restriction on external names?

It's my understanding that the reason that external identifiers in portable C programs had (still have?) to be unique in the first six characters is that six 6-bit characters¹ fill a 36-bit machine ...
user avatar
  • 1,388
9 votes
1 answer
1k views

What was the name of the object-oriented C language I used in the 1980s on the Mac

I clearly recall working with an object-oriented C derivative on the Mac but I cannot find any definitive references to it. It was back in the days of System 7 and later System 8. It had both ...
user avatar
9 votes
1 answer
533 views

Which pre-ANSI C compilers allowed a conditional expression as Lvalue?

Soon after learning the C language in the late 80s, before an ANSI C compiler was available on the machines I was using, it occurred to me to check if the following compiles int a, b, c; foo() { (...
user avatar
  • 15.8k
8 votes
2 answers
743 views

How can I malloc() a block that's guaranteed to lie within a single DMA segment in Turbo C 2.01?

I'm following root42's videos about DOS programming using Turbo C 2.01. I've written my own Soundblaster 1.xx driver following the Creative Labs documentation, and I'm confused about memory allocation....
user avatar
  • 9,875
8 votes
4 answers
2k views

Imaging a HDD from DOS over Serial

I have recently fixed an old IBM Clone, which has an MFM hard drive. The PC booted up fine, but then I saw, that a few years back, I have deleted a few important files (probably by mistake). The ...
user avatar
  • 363
7 votes
2 answers
647 views

Labels in cc65 inline assembler with #define macro

In general, it is possible to use inline assembler statements within C macros, for example #define toscreencode(C) (__AX__ = (C), \ asm("cmp #$60"),\ ...
user avatar
  • 4,080
6 votes
3 answers
1k views

Allocate 64 KiB in Watcom C 16-bit DOS

I'm trying to allocate a 64 KiB buffer in Watcom C 16-bit DOS. I'm using the "compact" memory model which defines the code segment to be limited to 64 KiB and addressed by near pointers (...
user avatar
  • 271
6 votes
3 answers
1k views

Why is modulo operation an operator for integer types but only a function for floating-point ones?

In C, we have the % operator which finds remainder of division. But it's only applicable to integral types. For floating-point types we have to use fmod function from math.h. This makes an impression ...
user avatar
  • 1,285
6 votes
2 answers
352 views

Why isn't the 'restrict' keyword useful in SDCC when compiling for Z80 target? [closed]

Context SDCC claims to support C11. I use it to write games on Z80 target (for fun and experience). C11 defines restrict C11 specifies the restrict keyword on pointers, which can improve generated ...
user avatar