3 ms·
I failed on one, number 4. I bravely assumed 16 bit integers cannot exist. Can anyone name a concrete platform/compiler where int is/was 16 bit. Or is this just
by usr1106 7y ago
I failed on one, number 4. I bravely assumed 16 bit integers cannot exist. Can anyone name a concrete platform/compiler where int is/was 16 bit. Or is this just a theoretical option left open by the spec?
- inamberclad 7y agoAVR, so certain Arduinos. On an Arduino Uno, sizeof(int) returns 2.
- segfaultbuserr 7y agoSo does AVR's (ex?) competitor, PIC8. This comes from the documentation of Microchip's C18 compiler. https://i.stack.imgur.com/1uV3l.jpg https://i.stack.imgur.com/1uV3l.jpg
- fengb 7y agoMost compilers for 8-bit and 16-bit CPUs, e.g. Z80 or 80286.
- segfaultbuserr 7y agoMany C compilers that target 8-bit (sometimes 16-bit) machines. MOS 6502, Zilog Z80, and Motorola 6809. Modern examples include Intel 8051, AVR and PIC.
- caf 7y agoTurbo C on MS-DOS for one. In fact 16-bit int was the norm on that platform, because the architecture didn't have 32-bit general purpose registers. In the C89 days, you'd use 'short' in aggregates (structs and array) for values you knew wouldn't exceed 16 bits so didn't want to potentially waste space; 'long' in situations where you knew 16 bits wouldn't be enough; and 'int' the rest of the time (where 16 bits was enough, and there weren't any storage benefits to outweigh the performance benefit of using the native word size).
- rcfox 7y agoMy first thought was MSDOS/Turbo C, and I found this page when looking for confirmation: http://synfare.com/599N105E/hwdocs/sizes.html http://synfare.com/599N105E/hwdocs/sizes.html
- WalterBright 7y agoDigital Mars C and C++ for DOS and (early) Windows.
- ummonk 7y agoI’ve worked with Arduinos where int was 16 bit.
- Sharlin 7y agoWhy couldn't they? C had already existed for a couple of decades when 32-bit machines started getting popular. `int`, as the default integer type, usually is the size of the machine word for best performance. It would make no sense to have slow, emulated 32-bit ´int`s on a 16-bit system, never mind 8-bit ones.
- peteri 7y agopdp-11
- Narishma 7y agox86 for one, up until 32-bit was introduced with the 80386.
- kurlberg 7y agoMy amiga c compiler (aztex manx) allowed either 16 or 32 bit ints. All/most systems libraries used 32 bit parameters, despite this I insisted on the 16 bit version "for performance". In hindsight this was sort of insane: one missing L (say in "1L" for casting to long) meant a not so quick floppy disk reboot). :-) Anyhow, for a computer with 16 bit wide data bus, having 16 bit ints might be justified by performance (and/or reducing memory usage.)