Hacker News new | comments | show | ask | jobs | submit login

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?

Yes; that's the distinction between "implementation-defined" and "undefined" behaviour.

While 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.

That 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.

I'd be surprised if it's non-deterministic, so yes.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact