Questions tagged [c]

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

Filter by
Sorted by
Tagged with
4 votes
1 answer
299 views

How to use external asm function in "vscode-amiga-debug" cross compiler?

I would like to write functions in assembly along with the c source code, but somehow I can't find the syntax. I tried e.g. in the fname.asm file (simplified): fill_bmap: rts In the fname.c ...
Tamás Putz's user avatar
5 votes
1 answer
278 views

Where to find the Cray arithmetic library?

Given a Cray simulator and a pre-installed UniCOS HD image, attempting to compile Steven Pemberton's ENQUIRE (literally, the second thing to try after "Hello, Cray") fails with CC-1153 cc: ...
Leo B.'s user avatar
  • 19.1k
3 votes
1 answer
680 views

What do the pins D0-D7 on the Intel 8080 exactly signify?

I am currently trying to create a FPGA styled simulator of the 8080 in C. I have a couple of questions regarding the D0-D7 pins. As far as I can see the D0-D7 lines are used in order to store data (a ...
cdunku's user avatar
  • 31
15 votes
2 answers
848 views

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&...
Chi_Iroh's user avatar
  • 253
4 votes
2 answers
2k views

Gameboy Key Input Causes Crash

I made a Key Tester using the STDIO header included with GBDK. It works... Until it doesn't. All the keys register and print to the screen, except the Left(5) and Right(4) Directional Keys, which ...
OPM eStudio's user avatar
3 votes
2 answers
447 views

Why does my MZ executable's BSS inflate by ~1,5KB after linking fopen() with MSC?

For a game reversing project, I am trying to undo linking with the C library performed by the MSC 5.1 C compiler+linker. To that end, I have created a simple executable that does nothing except ...
neuviemeporte's user avatar
32 votes
11 answers
12k views

Has there ever been a C compiler where using ++i was faster than i++?

Please take a look at this post: Is there a performance difference between i++ and ++i in C? There are two essential statements in the answer: Modern compiler produce the same machine code no matter ...
zomega's user avatar
  • 5,372
23 votes
2 answers
3k views

Using Clang to compile MS-DOS executables

I have a simple C program, and I would like to compile it targeting MS-DOS. Can this be achieved with Clang? I would like to produce the following formats: COM executable 16-bit MZ executable 32-bit ...
tpimh's user avatar
  • 430
5 votes
5 answers
804 views

Are there any statistics or data showing how much more productive the C programming language is compared to x86 assembly language?

I found out today that a large project like Microsoft Windows 1.0 took 80 man-years to develop. And this one was written in x86 assembly language. Is there a form or rule of thumb that states how much ...
Coder's user avatar
  • 1,068
10 votes
3 answers
905 views

How can I make the Microsoft C compiler for DOS emit a loop with an intermediate jump to continue?

I am trying to recreate the exact C source code from some 16bit DOS 8086 assembly generated by the MS C 5.0 compiler. After making some progress, I've hit a wall with the following code (annotated in ...
neuviemeporte's user avatar
8 votes
1 answer
647 views

How to make Microsoft C for MS-DOS emit an immediate-target far call into the data segment?

I am trying to recreate the C source code from some 16bit DOS 8086 assembly generated by the MS C 5.0 compiler. I've hit a wall with this far call instruction. 0000008D 9A2F0CB506 call 0x6b5:...
neuviemeporte's user avatar
6 votes
1 answer
388 views

What is the earliest use in C of indexing the bits of a float or double to sample a table lookup?

One common way to produce an approximation of a function like the logarithm or the exponential is to precompute a table of values (a lookup table) for the output or some intermediate stage of the ...
Adam Hyland's user avatar
29 votes
10 answers
10k views

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&...
Michael Stachowsky's user avatar
17 votes
2 answers
2k views

When did type punning through violating the strict aliasing rule become disallowed?

Looking at the C code from the Fast Inverse Square Root, the casting of a float to a long is done via pointer arithmetic: i = * ( long * ) &y; // evil floating point bit level hacking The ...
Adam Hyland's user avatar
8 votes
2 answers
975 views

Tiny libc for DOS 8086

I'm looking for a tiny libc (C runtime library) targeting small model DOS 8086, and providing (most of) the C89 library functions, including fread(...), printf(...) and scanf(...). The libc must work ...
pts's user avatar
  • 1,993
49 votes
7 answers
36k views

How could early UNIX OS comprise so few lines of code?

I start my journey to become a hardware / software specialist with an internship in two weeks time and decided to start studying the C language early. I came across this video, Learn C Programming ...
Neil Meyer's user avatar
  • 6,487
21 votes
2 answers
693 views

What is the history of SysV i386 calling convention for struct return?

I would like to understand historical roots of the quirk in the SysV calling convention for the 32-bit x86, which was inherited by the ELF standard, and so remains used on Linux to this day. Consider ...
amonakov's user avatar
  • 313
23 votes
8 answers
7k views

Why were nested functions excluded from B and C?

I'm learning C and was curious as to why the language does not allow nested functions. From what I've read, the lack of nested functions seems to have been a simplification that was inherited from its ...
user51462's user avatar
  • 331
9 votes
1 answer
501 views

Was the design of the PDP-11 Floating Point Processor responsible for C's willingness to do arithmetic on floats at double precision?

The Wikipedia page on PDP-11 architecture has a very interesting bullet point in the section on the Floating Point Processor extension to the basic architecture: full floating point operations on ...
John Dallman's user avatar
  • 13.2k
30 votes
3 answers
5k views

Most modern C compilers targeting DOS 8086, running on DOS 8086 (16-bit)

I'm looking for the most recent versions of modern C compilers which were/are targeting DOS 8086, also running on DOS 8086 (16-bit). I'm mostly interested in production-ready C compilers, rather than ...
pts's user avatar
  • 1,993
9 votes
1 answer
2k views

What is the meaning of asctime?

I see asctime in C, C++ and Python. What does the abbreviation mean? All those functions of max 8 characters are pretty obvious (strcpy e.g.) but this one eludes me. Is it ASCII time? Is it 'as ctime' ...
Michiel van der Blonk's user avatar
22 votes
1 answer
596 views

Where is Mike Lesk's (circa 1973) "portable I/O package" for C?

According to Dennis Ritchie's 1993 paper The Development of the C Language: Also during this period, the compiler was retargeted to other nearby machines, particularly the Honeywell 635 and IBM 360/...
Simon Kissane's user avatar
15 votes
1 answer
937 views

Why would an implementation of getwd call mktemp?

As mentioned here the book Expert C Programming contains the claim that there was a bug in SunOS 4.0.3's version of lpr, (a printing program) caused by a custom mktemp function overriding the library ...
Ryan1729's user avatar
  • 525
18 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 ...
Michael Stachowsky's user avatar
33 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 ...
Michael Stachowsky's user avatar
1 vote
0 answers
236 views

DirectX 8 Win32 GUI Not Appearing/Flickering While Running

I am programming a game with DirectX 8, and I am trying to use the GUI options that are provided by the Win32 window that I am using. However, when I try to render a button or, in this case, a textbox ...
rjhwinner03's user avatar
9 votes
2 answers
686 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 ...
Toby Speight's user avatar
  • 1,678
11 votes
3 answers
2k 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 ...
DannyNiu's user avatar
  • 365
42 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 ...
hefe's user avatar
  • 661
3 votes
1 answer
203 views

CC65 ignores request to correctly offset memory areas in output files

I'm trying to segment my C code into two distinct memory areas, one which will be flashed to a ROM chip and another which will end up somewhere else. Here is what I have in sbc.cfg (I was originally ...
ifconfig's user avatar
  • 133
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:...
DrSheldon's user avatar
  • 16k
24 votes
11 answers
11k 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 ...
Synthetix's user avatar
  • 341
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 ...
ajxs's user avatar
  • 836
20 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 ...
SZIEBERTH Ádám's user avatar
3 votes
1 answer
245 views

How to remove ___EXPORTEDSTUB statement from a NE (Win16) program's MAP?

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 ...
SZIEBERTH Ádám's user avatar
-2 votes
2 answers
353 views

1980s version of printf in C [closed]

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]); ...
Niklas Rosencrantz's user avatar
49 votes
3 answers
7k 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 ...
Peter Green's user avatar
  • 2,912
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 ...
Alexis Wilke's user avatar
60 votes
4 answers
12k 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 ...
hb20007's user avatar
  • 653
2 votes
1 answer
219 views

Where can I find the software for "DESIGN: a program to create data entry programs" by J. Michael Wuerth?

I have a copy of the book, DESIGN: a program to create data entry programs by J. Michael Wuerth. Does anyone know where I can obtain a copy of the accompanying software for the book?
Wes Robinson's user avatar
9 votes
1 answer
622 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() { (...
Leo B.'s user avatar
  • 19.1k
3 votes
1 answer
545 views

Did DEMOS have a C compiler?

DEMOS was a Soviet operating system derived from BSD Unix. The answer to this question shows that the familiar, English-derived BSD commands were essentially the same in DEMOS. Did DEMOS have a C ...
DrSheldon's user avatar
  • 16k
2 votes
1 answer
398 views

Microsoft C 6, far pointer, cast to int, warning C4047

Trying to access one byte in memory using segment/offset, like this union REGS in, out; struct SEGS segs; int v; char _far* p; ... int86x(...,&in,&out,&segs); p = (segs.es << 16) + ...
Tomas By's user avatar
  • 2,082
29 votes
1 answer
5k 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 ...
Omar and Lorraine's user avatar
1 vote
1 answer
228 views

When did cross-platform C start assuming function prototypes? [closed]

The most important difference between the original 'K&R' C, and ANSI/ISO C89/90, was function prototypes. These started being supported by some compilers in the mid-eighties, were formally ...
rwallace's user avatar
  • 61k
37 votes
6 answers
6k 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 ...
Calvin Godfrey's user avatar
31 votes
3 answers
5k 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 ...
user3840170's user avatar
  • 23.1k
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: ...
Michael Stum's user avatar
  • 1,680
7 votes
2 answers
931 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"),\ ...
Peter B.'s user avatar
  • 4,447
15 votes
4 answers
3k 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 ...
DannyNiu's user avatar
  • 365