[Info-vax] C compiler question
John E. Malmberg
wb8tyw at qsl.net_work
Mon Jul 29 09:05:47 EDT 2019
On 7/27/2019 11:57 AM, Mark Berryman wrote:
> Something I see all the time when porting unix code is something similar
> to the following:
>
> unsigned int x;
> .
> .
> .
> if (x <= 0) {something}
>
> This, of course, generates a QUESTCOMPARE informational. I'm wondering
> what code the compiler generates in such a case. Does it treat the
> variable as if it had been declared signed or does it do something else?
> Is the compiler's behavior in this case defined by a standard or is it
> left up to the implementation?
By the standard. "x" gets promoted to a signed type which preserves the
negative value.
This is unavoidable in porting code since many standard routines are
allowed to have a prototype return an unsigned type, yet specify a
negative value for errors.
> Part of what I am wondering is if I can count on the code generated by a
> VMS compiler to function the same as the code generated by a gcc or
> clang compiler.
I had the same concerns until the relevant section of the C standard was
shown to me. I think it was on comp.os.vms that I may have asked about
it a few years ago.
Regards,
-John
wb8tyw at qsl.net_work
More information about the Info-vax
mailing list