Issue Details (XML | Word | Printable)

Key: PCC-460
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Anders Magnusson
Reporter: Volkmar Klatt
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
pcc

issue with bitwise negation

Created: 03/Aug/14 01:07 AM   Updated: 03/Aug/14 07:49 PM
Component/s: None
Affects Version/s: None
Fix Version/s: None

File Attachments: 1. Text File tr_20140731_46.c (0.8 kB)

Environment: pcc 1.1.0.DEVEL 20140729 for i686-pc-linux-gnu


 Description  « Hide
/* tr_20140731_46.c - test file for pcc, Volkmar Klatt

   The bitwise negation of an
   unsigned bitfield var
   gives an integer (and so may overflow)

   I was wondering if this is OK, as C says nothing about
   the representation of bits in bitfields -
   then it's just an incompatility with gcc, clang, cparser, ...

   on the other hand:
  "for an unsigned operand e, ~e has the value
   UINT_MAX - e if the converted type of e is unsigned, or
   ULONG_MAX -e if the converted type of e is unsigned long."
       Harbison Steele, Section 7.5 (Unary Expressions, p. 223 in edition 5)
*/
#include <stdio.h>

struct S {
   unsigned f : 22;
};

struct S s = {1};

int main(void)
{
    int x;

    x = ((~s.f) < 0);
    printf("%i\n", x);

    printf("%i\n", ~s.f);
    printf("%u\n", ~s.f);

    return 0;
}




 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Anders Magnusson made changes - 03/Aug/14 07:48 PM
Field Original Value New Value
Assignee Anders Magnusson [ ragge ]
Anders Magnusson made changes - 03/Aug/14 07:49 PM
Status Open [ 1 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]