• AVR Freaks

Hot!int32_t --> warning: (759) expression generates no code (int16_t, int8_t --> no warning)

Author
sjb741
Super Member
  • Total Posts : 805
  • Reward points : 0
  • Joined: 2010/01/25 08:45:39
  • Location: 0
  • Status: offline
2019/06/06 10:51:15 (permalink)
0

int32_t --> warning: (759) expression generates no code (int16_t, int8_t --> no warning)

//XC8 v2.05
void Debug(void)
{
   //int8_t iTemp;   //OK
   //int16_t iTemp;    //OK
   int32_t iTemp;  //Warning
   
   #define TestMax(x,y) (x>y?x:y)
   iTemp = (PORTA<PORTC?PORTA:PORTC);  //OK
   iTemp = TestMax(PORTA,PORTC);       //OK
/*
   The following yield "expression generates no code" when iTemp is "int32_t"
   However, when iTemp has type "int16_t" or "int8_t" I do not see this warning
*/   
   iTemp = TestMax(PORTA,iTemp);
   iTemp = TestMax(0, iTemp);
   iTemp = TestMax(0, iTemp);
   iTemp = TestMax(9, iTemp);
   
   TMR2 = iTemp;
}//Debug
#1

15 Replies Related Threads

    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11208
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: int32_t --> warning: (759) expression generates no code (int16_t, int8_t --> no warnin 2019/06/06 11:06:02 (permalink)
    +2 (2)
    iTemp = TestMax(PORTA,iTemp);
       iTemp = TestMax(0, iTemp);
       iTemp = TestMax(0, iTemp);
       iTemp = TestMax(9, iTemp);

     
    If this is your actual code, the compiler is free to optimize away the first three statements, which may be what you're seeing.  Try it with a single assignment to iTemp.
     
    And your macro is a bug waiting to happen.  I would suggest
     
    #define TestMax(x,y) ((x)>(y)?(x):(y))
     
    #2
    sjb741
    Super Member
    • Total Posts : 805
    • Reward points : 0
    • Joined: 2010/01/25 08:45:39
    • Location: 0
    • Status: offline
    Re: int32_t --> warning: (759) expression generates no code (int16_t, int8_t --> no warnin 2019/06/06 11:23:10 (permalink)
    0
    I'd forgotten about the need for extra parenthesis, so thank you for pointing out the potential pitfall.
     
    It's just example code so I would not have the optimisation issue. All those superflous lines are just my trying to understand the problem.
     
    The problem persists though:
    //XC8 v2.05
    void Debug(void)
    {
       //int8_t iTemp;   //OK
       //int16_t iTemp;    //OK
       int32_t iTemp;  //Warning
       
       #define TestMax(x,y) (x>y?x:y)
    /*
       The following yield "expression generates no code" when iTemp is "int32_t"
       However, when iTemp has type "int16_t" or "int8_t" I do not see this warning
    */   
       iTemp = TestMax(9, iTemp);
       
       TMR2 = iTemp;
    }//Debug


    #3
    1and0
    Access is Denied
    • Total Posts : 9287
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: int32_t --> warning: (759) expression generates no code (int16_t, int8_t --> no warnin 2019/06/06 11:23:55 (permalink)
    0
    This generates the warning too with XC8 v1.45
    void Debug(void)
    {
        int16_t iTemp;   // int32_t warning too


        iTemp = PORTC;
        iTemp = (9 > iTemp) ? 9 : iTemp;

        TMR2 = iTemp;
    }//Debug

    #4
    1and0
    Access is Denied
    • Total Posts : 9287
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: int32_t --> warning: (759) expression generates no code (int16_t, int8_t --> no warnin 2019/06/06 11:31:42 (permalink)
    0
    This makes the warning disappear:
    iTemp = (9uL > iTemp) ? 9uL : iTemp;

     
    Edit: So does this
    iTemp = TestMax(9uL, iTemp);

    but this gives warning
    iTemp = TestMax(9L, iTemp);

    post edited by 1and0 - 2019/06/06 11:36:40
    #5
    1and0
    Access is Denied
    • Total Posts : 9287
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: int32_t --> warning: (759) expression generates no code (int16_t, int8_t --> no warnin 2019/06/06 11:53:39 (permalink)
    0
    I kinda see why it generates the warning, but do not understand when it does not generate the warning; e.g.
    if (9 > iTemp)
        iTemp = 9;
    else
        iTemp = iTemp; // no need to generate code here

    #6
    sjb741
    Super Member
    • Total Posts : 805
    • Reward points : 0
    • Joined: 2010/01/25 08:45:39
    • Location: 0
    • Status: offline
    Re: int32_t --> warning: (759) expression generates no code (int16_t, int8_t --> no warnin 2019/06/08 02:02:34 (permalink)
    0
    That is a useful way to look at it, clearly showing the final line does nothing. That does explain the warning, although other, closely related issues are now exposed.
     
    As you say: Why no warning with 8 or 16 bit? If I'd not tried 32 bit, I'd never have seen the warning.
     
    For the ternary operator, the warning would ideally identify which branch, True|False trips the warning. Altering the layout of the expression does not narrow the warning down.
       iTemp =
       (
          9 > iTemp? 9
          : iTemp
       );//Just reports on the entire expression
     
    #7
    1and0
    Access is Denied
    • Total Posts : 9287
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: int32_t --> warning: (759) expression generates no code (int16_t, int8_t --> no warnin 2019/06/08 07:05:36 (permalink)
    +1 (1)
    sjb741
    As you say: Why no warning with 8 or 16 bit? If I'd not tried 32 bit, I'd never have seen the warning.

    With XC8 v1.45 I get warning for 16-bit too.
     

    For the ternary operator, the warning would ideally identify which branch, True|False trips the warning. Altering the layout of the expression does not narrow the warning down.
       iTemp =
      (
         9 > iTemp? 9
         : iTemp
      );//Just reports on the entire expression

    That is easy to identify ;) Replacing the suspected branch with something that you know will generate code
     iTemp = (9 > iTemp) ? 9 : iVar;

    and the warning should disappear.
    #8
    InvalidApple
    Super Member
    • Total Posts : 295
    • Reward points : 0
    • Joined: 2011/05/17 23:36:35
    • Location: Melbourne, Australia
    • Status: offline
    Re: int32_t --> warning: (759) expression generates no code (int16_t, int8_t --> no warnin 2019/06/10 22:49:26 (permalink)
    +2 (2)
    The usual warning you'd get is "value set but not used" - So no code is generated for that statement.
     
    You could do something like this...

     
     
     
    #define CONST_CEILING(num, c) do{if ((num) > (c)) (num) = (c);} while(0)
     
     
     

    ... But even that is a bug waiting to happen - Think of what happens if I put ++ or -- in the num...

     
     
     
    while(i < calculatedNumber)
     
     
     
    {
     
     
     
      CONST_CEILING(++i, MAX_VALUE);
     
     
     
      doSomething(i);
     
     
     
    }
     
     
     

     
    The safest way to do it is to either just use a function, or type out what you want to happen.
     
     
    Just out of curiousity, was that code that you wrote supposed to do anything?  It just seems strange that you would do that - Especially the comparison to 0 twice in a row...
    post edited by InvalidApple - 2019/06/10 22:52:17
    #9
    sjb741
    Super Member
    • Total Posts : 805
    • Reward points : 0
    • Joined: 2010/01/25 08:45:39
    • Location: 0
    • Status: offline
    Re: int32_t --> warning: (759) expression generates no code (int16_t, int8_t --> no warnin 2019/06/19 06:33:43 (permalink)
    0
    The example was derived from a 'clamp value' operation using the Max and Min macros. It seemed neater/shorter code than using an 'if', even to clamp 'one way'.
     
    To clamp both ways, I put a Min as one of the Max arguments or vice versa.
    #10
    1and0
    Access is Denied
    • Total Posts : 9287
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: int32_t --> warning: (759) expression generates no code (int16_t, int8_t --> no warnin 2019/06/19 07:01:20 (permalink)
    +1 (1)
    sjb741
    The example was derived from a 'clamp value' operation using the Max and Min macros. It seemed neater/shorter code than using an 'if', even to clamp 'one way'.

    I'm not so sure about that macro being neater or shorter. What you are doing is just this:
    if (iTemp < 9)
       iTemp = 9;

    which seems readable enough.
    #11
    LdB_ECM
    Senior Member
    • Total Posts : 106
    • Reward points : 0
    • Joined: 2019/04/16 22:01:25
    • Location: 0
    • Status: offline
    Re: int32_t --> warning: (759) expression generates no code (int16_t, int8_t --> no warnin 2019/06/19 10:21:32 (permalink)
    0
    The macro fails because it is jibberish .. 1and0 has written the only intelligent thing but I think he meant ">"
    This is junk.
    iTemp = (9 > iTemp) ? 9 : iTemp;

    Gee if temp is less than or equal to 9 I can keep what I already have in the register .. how kind of you to tell me that.
    Oh and it doesn't generate any code ... you don't say.
    The art of writing what is blatantly simple in a longer form
     
    What is happening with the playing around is if you create a sign conversion between signed and unsigned it may need to deal with that so it doesn't complain .. hence this stoping the warning based solely on that.
    iTemp = (9uL > iTemp) ? 9uL : iTemp;

     
    If it really is need as a macro try a macro of what 1and0 wrote
    MaxLimit(a, b)  (if (a > b) a = b)

     
    post edited by LdB_ECM - 2019/06/19 10:23:59
    #12
    1and0
    Access is Denied
    • Total Posts : 9287
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: int32_t --> warning: (759) expression generates no code (int16_t, int8_t --> no warnin 2019/06/19 10:29:49 (permalink)
    0
    LdB_ECM
    .. 1and0 has written the only intelligent thing but I think he meant ">"

    No.  (iTemp < 9) is same as (9 > iTemp) ... hehe.
    post edited by 1and0 - 2019/06/19 10:34:44
    #13
    InvalidApple
    Super Member
    • Total Posts : 295
    • Reward points : 0
    • Joined: 2011/05/17 23:36:35
    • Location: Melbourne, Australia
    • Status: offline
    Re: int32_t --> warning: (759) expression generates no code (int16_t, int8_t --> no warnin 2019/06/19 17:45:04 (permalink)
    0

    If it really is need as a macro try a macro of what 1and0 wrote
    MaxLimit(a, b)  (if (a > b) a = b)


    Just quickly testing that on my computer did not compile (compiler mingw):
    D:\Programming\AlgorithmTest\main.c|6|error: expected expression before 'if'|
     
    There are a few other problems with using macros in general that are not considered - See here
     
     
    #14
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11208
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: int32_t --> warning: (759) expression generates no code (int16_t, int8_t --> no warnin 2019/06/19 19:11:50 (permalink)
    +2 (2)
    Yes, that macro is quite broken.  Maybe something like this instead:
    #define MaxLimit(a, b)  do { if ((a) > (b)) (a) = (b); } while(0)



    #15
    InvalidApple
    Super Member
    • Total Posts : 295
    • Reward points : 0
    • Joined: 2011/05/17 23:36:35
    • Location: Melbourne, Australia
    • Status: offline
    Re: int32_t --> warning: (759) expression generates no code (int16_t, int8_t --> no warnin 2019/06/19 20:36:44 (permalink)
    +3 (3)
    jtemples
    Yes, that macro is quite broken.  Maybe something like this instead:
    #define MaxLimit(a, b)  do { if ((a) > (b)) (a) = (b); } while(0)




    And make sure that it is labelled with only upper case letters - That is the convention for defined things and gives a clue that it is not a normal function :)
     
    #define MAXLIMIT(a, b)  do { if ((a) > (b)) (a) = (b); } while(0)

    #16
    Jump to:
    © 2019 APG vNext Commercial Version 4.5