Questions tagged [c]
The C programming language: its historical aspects and use on/targetting retro platforms.
93
questions
23
votes
10
answers
7k
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 ...
22
votes
2
answers
2k
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 ...
5
votes
5
answers
672
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 ...
11
votes
2
answers
996
views
How do I stop the Flickering on Mode 13h?
I'm making a Small Graphics Library for MS-DOS 6.22, using mode 13h with Turbo C on Vbox.
Recently, I was able to code a small snippet to move a sprite on the screen, using double buffering and I saw ...
5
votes
1
answer
521
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 ...
8
votes
1
answer
529
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:...
6
votes
1
answer
325
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 ...
29
votes
10
answers
9k
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&...
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 ...
8
votes
2
answers
733
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 ...
31
votes
6
answers
10k
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 ...
20
votes
2
answers
556
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 ...
22
votes
8
answers
6k
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 ...
9
votes
1
answer
443
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 ...
25
votes
3
answers
3k
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 ...
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' ...
21
votes
1
answer
550
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/...
15
votes
1
answer
917
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 ...
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 ...
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 ...
1
vote
0
answers
154
views
DirectX 8 Win32 GUI Not Appearing/Flickering While Running [closed]
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 ...
9
votes
2
answers
615
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 ...
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 ...
41
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 ...
3
votes
1
answer
170
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 ...
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:...
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 ...
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 ...
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 ...
3
votes
1
answer
195
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 ...
-2
votes
2
answers
340
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]);
...
48
votes
3
answers
6k
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 ...
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 ...
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 ...
2
votes
1
answer
203
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?
9
votes
1
answer
576
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() {
(...
1
vote
1
answer
363
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 ...
2
votes
1
answer
354
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) + ...
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 ...
1
vote
1
answer
218
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 ...
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 ...
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 ...
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:
...
7
votes
2
answers
792
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"),\
...
12
votes
3
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 ...
20
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 ...
2
votes
2
answers
271
views
Why isn't this invocation of XMS function Move EMB 0Bh in Turbo C correct?
Following on from my last question, I cannot get Move Extended Memory Block (Function 0Bh) working in Turbo C 2.01.
The following main.c contains only the minimum functions: get the XMS driver pointer,...
8
votes
2
answers
865
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....
0
votes
3
answers
322
views
Should C be regarded as an Intermediate Language? [closed]
Should C be regarded as an intermediate language on a virtual machine named PDP-11 Architecture (which have a plain memory space and stacks), like opcode to jvm, msil to dotnet, asm.js to v8, which ...
2
votes
0
answers
196
views
Hitting the CMS Limits of Portable Code
I wrote this arbitrary precision arithmetic utility on BSD in my postgraduate days, then after graduating ported it to DOS using TurboC. Was proud that it would do the same thing with 16bit word ...