bitwise not operator

  • Thread starter Mantorok Redgormor
  • Start date
M

Mantorok Redgormor

Should I avoid its use? It seems its use from alot of other posts that
I have read is discouraged because a discussion always begins on how
implementation defined behavior occurs with it.

~0 [ this is not well defined right? ]
[ if anyone ever used this in code it would not be portable? ]

~-1 [ well defined? ]

~25 [ well defined? ]

etc..
 
D

Dan Pop

In said:
Should I avoid its use? It seems its use from alot of other posts that
I have read is discouraged because a discussion always begins on how
implementation defined behavior occurs with it.

~0 [ this is not well defined right? ]
[ if anyone ever used this in code it would not be portable? ]

~-1 [ well defined? ]

~25 [ well defined? ]

It is well defined on unsigned operands only. The result on signed
operands is implementation-defined, because the standard allows more than
one representation for negative values. Furthermore, depending on the C99
implementation, applying it to certain signed values may result in trap
representations (e.g. ~INT_MAX for two's complement and sign-magnitude
and ~0 for one's complement).

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top