3 ms·
This confirms that it was conceived pretty much as a typeless language. The purpose of "char" was to be able to process byte-addressed strings character by char
by bluetomcat 4y ago
This confirms that it was conceived pretty much as a typeless language. The purpose of "char" was to be able to process byte-addressed strings character by character, and to do byte-sized pointer arithmetic without any runtime conversions. For most other purposes, "int" was the machine word. Hence the weak typing and the odd conversion and promotion rules between "char" and "int".
- kragen 4y agoyes, b (like bcpl) was completely untyped, and in c both int and pointers were machine words (and in 6th edition c typing was very weak indeed), but you have the pointer arithmetic thing backwards on a byte-addressed machine, byte pointer arithmetic works fine if you treat the byte pointers as integers and don't do any conversions at dereference time; that's what it means to be a byte-addressed machine usually (certainly in the case of the pdp-11) it's pointers to larger-than-byte things (ints, pointers, and later floats, structs, and arrays) where runtime conversions rear their head; if you try to not distinguish between ints and pointers to ints, then for *(p+1) to refer to the int after *p (instead of one overlapping it, giving a bus error), you need to shift p left by one bit at dereference time, or two bits on a 32-bit machine (if its memory addresses identify 8-bit bytes, as on the 360, pdp-11, vax, and 8086). no such conversion is required for char pointers hope this clarifies