Is there an implicit type promotion in “float = float - float”?Implicit type conversion rules in C++ operatorsImplicit type conversion in CHow is float variable auto-promoted to double type?What are POD types in C++?Do the parentheses after the type name make a difference with new?Writing containers that can handle implicit sharing, but turn it off for non-copyable types (like unique_ptr)?Implicit conversion in C++C++ Member variables confusionImplicit conversion of both operands for operator==C++ modulus operator with float using #define and own classImplicit conversion to float using avr-gcc: uint8_t vs. uint16_tReusing a float buffer for doubles without undefined behaviourWhen does implicit type conversion occur in C++?

What does air vanishing on contact sound like?

Hang 20lb projector screen on Hardieplank

Password expiration with Password manager

Was Hulk present at this event?

What are the spoon bit of a spoon and fork bit of a fork called?

How to reply this mail from potential PhD professor?

What is the most remote airport from the center of the city it supposedly serves?

Entropy as a function of temperature: is temperature well defined?

Is this homebrew race based on the Draco Volans lizard species balanced?

Unidentified items in bicycle tube repair kit

How can I close a gap between my fence and my neighbor's that's on his side of the property line?

Historically, were women trained for obligatory wars? Or did they serve some other military function?

What word means "to make something obsolete"?

Binary Numbers Magic Trick

Power LED from 3.3V Power Pin without Resistor

Who died in the Game of Thrones episode, "The Long Night"?

Disabling Resource Governor in SQL Server

I caught several of my students plagiarizing. Could it be my fault as a teacher?

Is balancing necessary on a full-wheel change?

What happened to Ghost?

Why was Germany not as successful as other Europeans in establishing overseas colonies?

How do I tell my manager that his code review comment is wrong?

Floor tile layout process?

Write to EXCEL from SQL DB using VBA script



Is there an implicit type promotion in “float = float - float”?


Implicit type conversion rules in C++ operatorsImplicit type conversion in CHow is float variable auto-promoted to double type?What are POD types in C++?Do the parentheses after the type name make a difference with new?Writing containers that can handle implicit sharing, but turn it off for non-copyable types (like unique_ptr)?Implicit conversion in C++C++ Member variables confusionImplicit conversion of both operands for operator==C++ modulus operator with float using #define and own classImplicit conversion to float using avr-gcc: uint8_t vs. uint16_tReusing a float buffer for doubles without undefined behaviourWhen does implicit type conversion occur in C++?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








11















We are using QA-C for MISRA C++ conformance, but the tool spews out an error for code like this:



float a = foo();
float b = bar();
float c = a - b;


As far as I understand, this has no implicit type promotion as everything will happen in float-sized chunks, but the tool tells me that the subtraction causes one. Is there any situation where there might be implicit promotion?










share|improve this question

















  • 13





    Would you mind adding the exact error that it gives you?

    – Max Langhof
    Apr 26 at 7:49






  • 1





    Consider also this Q&A, maybe, maybe the tool you are using is misinterpreting what's stated in the second part of that answer.

    – Bob__
    Apr 26 at 8:19






  • 3





    @Damon that's a non-sequitur; short is promoted to int in this case and yet it makes sense to have short

    – M.M
    Apr 26 at 12:06







  • 3





    @Damon you already quoted the text that says "integral promotion shall be performed on both" (not "is allowed to happen" or whatever).

    – M.M
    Apr 26 at 12:31






  • 2





    Please provide the actual error message and actual code that produces that error message.

    – Yakk - Adam Nevraumont
    Apr 26 at 13:54

















11















We are using QA-C for MISRA C++ conformance, but the tool spews out an error for code like this:



float a = foo();
float b = bar();
float c = a - b;


As far as I understand, this has no implicit type promotion as everything will happen in float-sized chunks, but the tool tells me that the subtraction causes one. Is there any situation where there might be implicit promotion?










share|improve this question

















  • 13





    Would you mind adding the exact error that it gives you?

    – Max Langhof
    Apr 26 at 7:49






  • 1





    Consider also this Q&A, maybe, maybe the tool you are using is misinterpreting what's stated in the second part of that answer.

    – Bob__
    Apr 26 at 8:19






  • 3





    @Damon that's a non-sequitur; short is promoted to int in this case and yet it makes sense to have short

    – M.M
    Apr 26 at 12:06







  • 3





    @Damon you already quoted the text that says "integral promotion shall be performed on both" (not "is allowed to happen" or whatever).

    – M.M
    Apr 26 at 12:31






  • 2





    Please provide the actual error message and actual code that produces that error message.

    – Yakk - Adam Nevraumont
    Apr 26 at 13:54













11












11








11








We are using QA-C for MISRA C++ conformance, but the tool spews out an error for code like this:



float a = foo();
float b = bar();
float c = a - b;


As far as I understand, this has no implicit type promotion as everything will happen in float-sized chunks, but the tool tells me that the subtraction causes one. Is there any situation where there might be implicit promotion?










share|improve this question














We are using QA-C for MISRA C++ conformance, but the tool spews out an error for code like this:



float a = foo();
float b = bar();
float c = a - b;


As far as I understand, this has no implicit type promotion as everything will happen in float-sized chunks, but the tool tells me that the subtraction causes one. Is there any situation where there might be implicit promotion?







c++ language-lawyer qa-c






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Apr 26 at 7:45









Ken Y-NKen Y-N

7,996134776




7,996134776







  • 13





    Would you mind adding the exact error that it gives you?

    – Max Langhof
    Apr 26 at 7:49






  • 1





    Consider also this Q&A, maybe, maybe the tool you are using is misinterpreting what's stated in the second part of that answer.

    – Bob__
    Apr 26 at 8:19






  • 3





    @Damon that's a non-sequitur; short is promoted to int in this case and yet it makes sense to have short

    – M.M
    Apr 26 at 12:06







  • 3





    @Damon you already quoted the text that says "integral promotion shall be performed on both" (not "is allowed to happen" or whatever).

    – M.M
    Apr 26 at 12:31






  • 2





    Please provide the actual error message and actual code that produces that error message.

    – Yakk - Adam Nevraumont
    Apr 26 at 13:54












  • 13





    Would you mind adding the exact error that it gives you?

    – Max Langhof
    Apr 26 at 7:49






  • 1





    Consider also this Q&A, maybe, maybe the tool you are using is misinterpreting what's stated in the second part of that answer.

    – Bob__
    Apr 26 at 8:19






  • 3





    @Damon that's a non-sequitur; short is promoted to int in this case and yet it makes sense to have short

    – M.M
    Apr 26 at 12:06







  • 3





    @Damon you already quoted the text that says "integral promotion shall be performed on both" (not "is allowed to happen" or whatever).

    – M.M
    Apr 26 at 12:31






  • 2





    Please provide the actual error message and actual code that produces that error message.

    – Yakk - Adam Nevraumont
    Apr 26 at 13:54







13




13





Would you mind adding the exact error that it gives you?

– Max Langhof
Apr 26 at 7:49





Would you mind adding the exact error that it gives you?

– Max Langhof
Apr 26 at 7:49




1




1





Consider also this Q&A, maybe, maybe the tool you are using is misinterpreting what's stated in the second part of that answer.

– Bob__
Apr 26 at 8:19





Consider also this Q&A, maybe, maybe the tool you are using is misinterpreting what's stated in the second part of that answer.

– Bob__
Apr 26 at 8:19




3




3





@Damon that's a non-sequitur; short is promoted to int in this case and yet it makes sense to have short

– M.M
Apr 26 at 12:06






@Damon that's a non-sequitur; short is promoted to int in this case and yet it makes sense to have short

– M.M
Apr 26 at 12:06





3




3





@Damon you already quoted the text that says "integral promotion shall be performed on both" (not "is allowed to happen" or whatever).

– M.M
Apr 26 at 12:31





@Damon you already quoted the text that says "integral promotion shall be performed on both" (not "is allowed to happen" or whatever).

– M.M
Apr 26 at 12:31




2




2





Please provide the actual error message and actual code that produces that error message.

– Yakk - Adam Nevraumont
Apr 26 at 13:54





Please provide the actual error message and actual code that produces that error message.

– Yakk - Adam Nevraumont
Apr 26 at 13:54












1 Answer
1






active

oldest

votes


















15














There is no implicit promotion involved here.



When conversions involving binary operators are involved, they are called usual arithmetic conversions.



From C++ standard, [expr]/11:




11 Many binary operators that expect operands of arithmetic or enumeration type cause conversions and yield
result types in a similar way. The purpose is to yield a common type, which is also the type of the result.
This pattern is called the usual arithmetic conversions, which are defined as follows:

...

(11.4) — Otherwise, if either operand is float, the other shall be converted to float.




Since both operands are float in your example, there is no such conversion or promotion.

So this could be a false positive from the tool.






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55863031%2fis-there-an-implicit-type-promotion-in-float-float-float%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    15














    There is no implicit promotion involved here.



    When conversions involving binary operators are involved, they are called usual arithmetic conversions.



    From C++ standard, [expr]/11:




    11 Many binary operators that expect operands of arithmetic or enumeration type cause conversions and yield
    result types in a similar way. The purpose is to yield a common type, which is also the type of the result.
    This pattern is called the usual arithmetic conversions, which are defined as follows:

    ...

    (11.4) — Otherwise, if either operand is float, the other shall be converted to float.




    Since both operands are float in your example, there is no such conversion or promotion.

    So this could be a false positive from the tool.






    share|improve this answer





























      15














      There is no implicit promotion involved here.



      When conversions involving binary operators are involved, they are called usual arithmetic conversions.



      From C++ standard, [expr]/11:




      11 Many binary operators that expect operands of arithmetic or enumeration type cause conversions and yield
      result types in a similar way. The purpose is to yield a common type, which is also the type of the result.
      This pattern is called the usual arithmetic conversions, which are defined as follows:

      ...

      (11.4) — Otherwise, if either operand is float, the other shall be converted to float.




      Since both operands are float in your example, there is no such conversion or promotion.

      So this could be a false positive from the tool.






      share|improve this answer



























        15












        15








        15







        There is no implicit promotion involved here.



        When conversions involving binary operators are involved, they are called usual arithmetic conversions.



        From C++ standard, [expr]/11:




        11 Many binary operators that expect operands of arithmetic or enumeration type cause conversions and yield
        result types in a similar way. The purpose is to yield a common type, which is also the type of the result.
        This pattern is called the usual arithmetic conversions, which are defined as follows:

        ...

        (11.4) — Otherwise, if either operand is float, the other shall be converted to float.




        Since both operands are float in your example, there is no such conversion or promotion.

        So this could be a false positive from the tool.






        share|improve this answer















        There is no implicit promotion involved here.



        When conversions involving binary operators are involved, they are called usual arithmetic conversions.



        From C++ standard, [expr]/11:




        11 Many binary operators that expect operands of arithmetic or enumeration type cause conversions and yield
        result types in a similar way. The purpose is to yield a common type, which is also the type of the result.
        This pattern is called the usual arithmetic conversions, which are defined as follows:

        ...

        (11.4) — Otherwise, if either operand is float, the other shall be converted to float.




        Since both operands are float in your example, there is no such conversion or promotion.

        So this could be a false positive from the tool.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Apr 26 at 8:01

























        answered Apr 26 at 7:52









        P.WP.W

        19.6k41961




        19.6k41961





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55863031%2fis-there-an-implicit-type-promotion-in-float-float-float%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

            Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

            Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림