Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #12514

left shift count >= width of type

From Alessandro Basili <alessandro.basili@cern.ch>
Newsgroups comp.lang.c
Subject left shift count >= width of type
Date 2011-11-02 10:55 +0100
Message-ID <9hcichF56iU1@mid.individual.net> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

Hi,
here's a simple program snippet that I'm dealing with and worried about
potential pitfalls:

#define BITS_PER_UNIT 32
[...]
int foo, bar;

bar = 0xAAAA5555;
foo = bar & ~ ((int) 1 << BITS_PER_UNIT);
[...]

Strictly speaking the shift operations should report a warning (left
shift count >= width of type), since 1 is of type int (correct me if I'm
wrong).
Since this snippet is part of a very old implementation of g21k compiler
for ADSP21xxx, I'm wondering why do we need to shift at all, isn't the
above foo assignment equal to the following:

foo = bar;

Hope someone can clarify.

Al

-- 
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Back to comp.lang.c | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

left shift count >= width of type Alessandro Basili <alessandro.basili@cern.ch> - 2011-11-02 10:55 +0100
  Re: left shift count >= width of type James Kuyper <jameskuyper@verizon.net> - 2011-11-02 07:34 -0400
    Re: left shift count >= width of type Keith Thompson <kst-u@mib.org> - 2011-11-02 13:47 -0700
    Re: left shift count >= width of type Alessandro Basili <alessandro.basili@cern.ch> - 2011-11-04 17:46 +0100
      Re: left shift count >= width of type James Kuyper <jameskuyper@verizon.net> - 2011-11-04 13:12 -0400
        Re: left shift count >= width of type Alessandro Basili <alessandro.basili@cern.ch> - 2011-11-05 19:17 +0100
  Re: left shift count >= width of type Thad Smith <ThadSmith@acm.org> - 2011-11-02 20:22 -0600

csiph-web