3 ms·
Should the implementation-defined behavior be always the same? That is, char a = (char)128; char b = (char)128; Will a == b for every implementation?
by dchest 14y ago
Should the implementation-defined behavior be always the same? That is,
char a = (char)128;
char b = (char)128;
Will a == b for every implementation?
- lmm 14y agoYes; that's the distinction between "implementation-defined" and "undefined" behaviour.
- beagle3 14y agoWhile that's how it is generally understood, there is nothing stopping the implementation from defining the behaviour as: conversion is rounded up to the nearest multiple of 20 on odd lines. conversion is rounded down to the nearest multiple of 17 on even lines. Older versions of gcc would have such a (fully standard compliant) behavior when you used #pragma, that included running rogue or nethack and other stuff -- but later versions actually succumbed to implementing useful pragmas.
- TazeTSchnitzel 14y agoI'd be surprised if it's non-deterministic, so yes.
- dllthomas 14y agoThat depends on what you mean by "should". Is it required by the standard? AFAIK, no. Would it be a braindead decision on the part of the compiler writers to do otherwise? Almost certainly. In practice, the answer to > Will a == b for every implementation? is, I suspect, yes.