• AVR Freaks

Hot!"warning: (759) expression generates no code" WHY?

Author
Frank Everest
Junior Member
  • Total Posts : 103
  • Reward points : 0
  • Joined: 2006/09/24 04:07:59
  • Location: Stevenage, UK
  • Status: offline
2020/11/28 08:25:49 (permalink)
0

"warning: (759) expression generates no code" WHY?

I'm running MPLABX v5.45, and XC8 v2.31 compiler with the PRO dongle. The processor is 16F18254. The two variables divisor and dividend are both __int24's.  time_to_go is an unsigned int.
The lines are part of a function, and I get the above (759) warning at line 101. It says:
sums.c:101:: warning: (759) expression generates no code
sums.c:103:: warning: (760) portion of expression has no effect
...
100  if (divisor == 0) //catch division by zero:
101      time_to_go = 1990;
102  else
103      time_to_go = (unsigned int)(dividend/divisor);
 
Now I really want to be sure to catch division by zero, and can't see what's wrong with line 103 either. Can anyone steer me onto the right path, please?
#1

14 Replies Related Threads

    du00000001
    Just Some Member
    • Total Posts : 4071
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: "warning: (759) expression generates no code" WHY? 2020/11/28 08:54:37 (permalink)
    +4 (6)
    Let me guess: time_to_go is currently read/used nowhere.
    So, why should an optimizing compiler compute a variable that's never read?

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #2
    Frank Everest
    Junior Member
    • Total Posts : 103
    • Reward points : 0
    • Joined: 2006/09/24 04:07:59
    • Location: Stevenage, UK
    • Status: offline
    Re: "warning: (759) expression generates no code" WHY? 2020/11/28 09:06:28 (permalink)
    0
    You guess right! Doh.
     
    I've got the same code in two places with different target registers. sad: sad That'll teach me to use legacy code (of mine) without noticing that.
     
    It's a good thing someone's awake! Thanks for spotting that. 
    #3
    du00000001
    Just Some Member
    • Total Posts : 4071
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: "warning: (759) expression generates no code" WHY? 2020/11/28 09:40:14 (permalink)
    +2 (2)
    "Spotting that" is great - considering that you didn't provide more than this snippet of code.
    But the "generates no code" is a frequent "issue".
     
    Re: "... someone's awake ..."
    This is the w-w-w - somebody is always awake. It's 17.30 h local time (CET)  :)

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #4
    AndersG
    Super Member
    • Total Posts : 241
    • Reward points : 0
    • Joined: 2008/08/05 04:51:24
    • Location: 0
    • Status: offline
    Re: "warning: (759) expression generates no code" WHY? 2020/11/28 10:35:25 (permalink)
    0
    He, he. Just popped in to complain about this.. Ie:
     
    void foo(void)
    {
    int bar = 0;
    .. more code
    }

     
    I assume that it flags this as "generates no code" because local variables are automatically zeroed on creation?
     
     
    #5
    du00000001
    Just Some Member
    • Total Posts : 4071
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: "warning: (759) expression generates no code" WHY? 2020/11/28 11:02:06 (permalink)
    +1 (1)
    AndersG
    He, he. Just popped in to complain about this.. Ie:
     
    void foo(void)
    {
    int bar = 0;
    .. more code
    }

     
    I assume that it flags this as "generates no code" because local variables are automatically zeroed on creation?



    I assume you don't use (read) bar in the snipped code. Local variables are NOT initialized automatically.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #6
    Murton Pike Systems
    Super Member
    • Total Posts : 139
    • Reward points : 0
    • Joined: 2020/09/10 02:13:01
    • Location: 0
    • Status: offline
    Re: "warning: (759) expression generates no code" WHY? 2020/11/28 14:15:53 (permalink)
    -1 (1)
    if (ax==3);
     
    Another example of source code not generating any object code.
     
    #7
    Hen
    Super Member
    • Total Posts : 122
    • Reward points : 0
    • Joined: 2018/10/24 04:01:44
    • Location: 0
    • Status: offline
    Re: "warning: (759) expression generates no code" WHY? 2020/11/28 22:10:18 (permalink)
    0
    nigelwright7558
    if (ax==3);
    Another example of source code not generating any object code.

    Would that hold water even if:
    volatile int ax;
    #8
    ric
    Super Member
    • Total Posts : 29435
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: "warning: (759) expression generates no code" WHY? 2020/11/29 00:15:25 (permalink)
    -1 (3)
    nigelwright7558
    if (ax==3);
     
    Another example of source code not generating any object code.
     

    Impossible to comment without seeing the surrounding code.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #9
    crosland
    Super Member
    • Total Posts : 2142
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: offline
    Re: "warning: (759) expression generates no code" WHY? 2020/11/29 03:17:16 (permalink)
    +2 (2)
    nigelwright7558
    if (ax==3);
     
    Another example of source code not generating any object code.
     



    Another example of a completely pointless post devoid of any context.
    #10
    AndersG
    Super Member
    • Total Posts : 241
    • Reward points : 0
    • Joined: 2008/08/05 04:51:24
    • Location: 0
    • Status: offline
    Re: "warning: (759) expression generates no code" WHY? 2020/11/29 03:40:42 (permalink)
    0
    I assume you don't use (read) bar in the snipped code. Local variables are NOT initialized automatically.
    My mistake, the variable(s) it complained about were actually global ones.
    #11
    andersm
    Super Member
    • Total Posts : 2867
    • Reward points : 0
    • Joined: 2012/10/07 14:57:44
    • Location: 0
    • Status: online
    Re: "warning: (759) expression generates no code" WHY? 2020/11/29 03:57:13 (permalink)
    -1 (1)
    ric
    nigelwright7558
    if (ax==3);
     
    Another example of source code not generating any object code.
     

    Impossible to comment without seeing the surrounding code.
     

    It's an empty true-statement, so a NOP.

    if (ax == 3) {
    }

    #12
    ric
    Super Member
    • Total Posts : 29435
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: "warning: (759) expression generates no code" WHY? 2020/11/29 04:36:58 (permalink)
    0 (2)
    Good point. I missed the semi-colon, so didn't understand what he was getting at.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #13
    Murton Pike Systems
    Super Member
    • Total Posts : 139
    • Reward points : 0
    • Joined: 2020/09/10 02:13:01
    • Location: 0
    • Status: offline
    Re: "warning: (759) expression generates no code" WHY? 2020/11/29 08:21:53 (permalink)
    +1 (1)
    andersm
     
    It's an empty true-statement, so a NOP.

     
    if (ax == 3) {
     
    }





    Compiler says "generates no code"
     
    #14
    du00000001
    Just Some Member
    • Total Posts : 4071
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: "warning: (759) expression generates no code" WHY? 2020/11/29 09:16:30 (permalink)
    +2 (2)
    nigelwright7558
    andersm
     
    It's an empty true-statement, so a NOP.
     

    if (ax == 3) {
    }




    Compiler says "generates no code"



    An empty statement is not a NOP but just "nothing".
    Now, why should the compiler genrate code for the comparison if just nothing is to be done in the true-branch.
    Keep in mind that this compiler is optimizing!

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #15
    Jump to:
    © 2021 APG vNext Commercial Version 4.5