Thread: Semantics of bit inversion operator

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    1

    Question Semantics of bit inversion operator

    Hi,

    what is the return type of the operator~ for integral types? I thought no promotion needs to be done here, but from a question to the gcc-help mailing list I got the following explanations:
    The problem is that the operator "~" when applied upon the unsigned
    char returns always a signed char.
    and
    Integral promotions are performed for operator ~ and int can represent
    all the values of unsigned char, so the operand is promoted to int.
    So my questions are
    1. what are the promotion rules for bit inversion regarding integral types?
    2. is this behaviour implementation defined?


    bye,
    deVas

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by deVas
    what are the promotion rules for bit inversion regarding integral types?
    Integral promotion is performed.

    Quote Originally Posted by deVas
    is this behaviour implementation defined?
    No, though of course the details of the integral promotion itself is implementation defined.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. overloaded >> operator issue...
    By soulredemption in forum C++ Programming
    Replies: 2
    Last Post: 10-17-2005, 10:53 PM
  2. porting application from 32 bit to 64 bit error
    By gandalf_bar in forum Linux Programming
    Replies: 1
    Last Post: 09-14-2005, 09:20 AM
  3. C++ Operator Overloading help
    By Bartosz in forum C++ Programming
    Replies: 2
    Last Post: 08-17-2005, 12:55 PM
  4. Bit processing in C
    By eliomancini in forum C Programming
    Replies: 8
    Last Post: 06-07-2005, 10:54 AM
  5. Porting from 32 bit machine to 64 bit machine!
    By anoopks in forum C Programming
    Replies: 10
    Last Post: 02-25-2005, 08:02 PM

Tags for this Thread