This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: signed/unsigned integer conversion for right shift seems


On 07/02/18 10:59, Peter T. Breuer wrote:
> "Also sprach Jonathan Wakely:"
>>
>> On 6 February 2018 at 20:08, Tadeus Prastowo wrote:
>>> Jonathan is not attacking you.
>>
>> Well I am now, because he's insisting on continuing his off-topic
>> wanderings through the C standard.
> 
> The question is if gcc is following the C standard.

It is.  This has been explained to you, patiently and repeatedly, by
several people here.  You have been directed to the standards, and to
reference sites that are known to be accurate and reliable
(http://en.cppreference.com).  You have been requested, repeatedly and
politely, to take this discussion to an appropriate place if you want to
continue it.

No one is going to claim that gcc is perfect.  No one is going to claim
that the C standards are always clear and easy to follow.  But in this
case, the standards are unambiguous and gcc follows them correctly.  As
I see it, you have three sensible choices.

1. You can trust the experts on the matter.  (I don't know the
qualifications of other people in this thread, but Jonathan is/was
secretary of the C++ ISO working group.  If he says something about C,
C++ or gcc, you can be confident that it is correct.)

2. You can study the standards, and maybe you will understand it yourself.

3. You can ask /politely/ in an appropriate place, such as the
comp.std.c or comp.lang.c newsgroups.  Reading and listening to people,
rather than arguing, would help.

> 
> You are counselled not to do the attacking thing, unless you would like
> to be e-sat on and e-fingered by the e-police, or just generally
> villified and derided as that e-wit throughout the Internet and the
> e-iverse in general.

Patronising will not help your case.  Remember that in this mailing list
- in the context of gcc - Jonathan commands enormous respect, earned
from years of work on the compiler, libraries, and the languages
themselves.  You - in the context of this mailing list - are a nobody.
(I am not a gcc developer either - but I have no illusions of grandeur.)
 Be in no doubt that your writing here makes you look rude, ignorant,
and more like a spoiled teenager than a serious developer.

> 
> To summarize what we know:
> 
> 6.1.3.8 of many C standards contains a list of for what operators
> conversions should be applied "automatically", which means "without a
> cast", which means "implicitly".  That list is prescriptive except
> inasmuch as it is countermanded and/or overridden by the one-by-one
> details of the operators in 6.5.  There is nothing else that applies, as
> the authority at the start of section 6.1 says.

Section 6.3.1.8p1 describes the "usual arithmetic conversions" that
apply to many (not all) operators in order to determine a common real
type for the operands and result.  When there are no floating point
types involved, this includes performing "integer promotions" to both
operands individually, before finding the common type.

"Integer promotion" is always done for a /single/ object or expression,
and is distinct from finding a common type for two operands.  It is
described in 6.3.1.1p2.

These paragraphs describe how specific types of automatic conversions
are to be done - they do not say /when/ they are to be applied.

Details of which automatic conversions are applied to the operands of
different operators are given in 6.5.  For example, in 6.5.5p3 for
"Multiplicative operators" it says "The usual arithmetic conversions are
performed on the operands".  And in 6.5.7p3 for "Bitwise shift
operators", it says "The integer promotions are performed on each of the
operands".

/That/ is all you need.


Hopefully, that will cover everything.  If you have any more questions
on the subject, ask in the right place.  If you think the standards are
unclear, complain to the C standards committee and ask for an
improvement in the wording.  If you think the compiler is wrong, file a
bug report (it will be closed as invalid).

Other than that, you might like to post an apology and a thank-you to
the people in this list that have helped you.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]