Fwd: is there any word processing software for the pdp11?
Holm Tiffe
holm at freibergnet.de
Tue Dec 2 12:45:33 CST 2014
Jon Elson wrote:
[..]
>
> Boiling it down, we had :
>
> long long int A;
> int B;
> A = B << 32;
>
> This means that some field of B gets shifted to the right by
> 32 bits, and
> fit into the upper 32-bits of A.
>
> Now, any decent compiler should either extend B to the
> length of A, or
> as the C rules specify, NOT extend B, and therefor ought to
> warn you
> that it is losing significant bits. No warning, no
> extending the variable
> before shifting the bits off the end of the word. So, A
> always gets
> a zero! UGH! Stupid! I could almost write a book of these
> sorts
> of gotchas.
>
> Jon
No, thats not stupid. Nobody says that the compiler should think about your
code.
You clearly shift the int variable 32 times to the left and the compiler is
warning you..
BTW: there are some standards in stdint.h that clarify up a lot which tpe
has how many bits, eg int32_t int64_t uint8_t.
On my system int is 64 Bits and a long long is 128 bits, for shure your
code will work here, bit your code isn't portable! It doesn't work on a
32 Bit system and it doesn't work on 16 or 8 Bit machines.
C is much like Assembler, you should know what you really want todo. The
comiler let you do all kind of things with the assumption that you know what
you are doing. This is a programming language for system programming
purposes (written to write Unix) where you have to load unusual registers
and such things...
How about this:
A = (int64_t)B << 32;
Regards,
Holm
--
Technik Service u. Handel Tiffe, www.tsht.de, Holm Tiffe,
Freiberger Straße 42, 09600 Oberschöna, USt-Id: DE253710583
www.tsht.de, info at tsht.de, Fax +49 3731 74200, Mobil: 0172 8790 741
More information about the cctech
mailing list