3 ms·
Subtracting 1 from the user provided index isn't that expensive. Or, if you're willing to give up three bytes, index into "ErrSunMonTueWedThuFriSat". Or, and
by jefftk 4y ago
Subtracting 1 from the user provided index isn't that expensive.
Or, if you're willing to give up three bytes, index into "ErrSunMonTueWedThuFriSat".
Or, and this is mildly insane but perhaps in keeping with early C, have your pointer be three bytes before the beginning of "SunMonTueWedThuFriSat" and use one-based indexing.
- deleted 4y ago[deleted]
- Jtsummers 4y agoIt all boils down to the fact that C's memory model is meant to map closely to the physical memory model, and the C and Unix developers preferred simplicity of implementation over simplicity of interface. Leaky abstractions (like that the weekday or months start at 0 so that they can reference into arrays of names) are fine given that prioritization. Not everyone shares that preference.