• AVR Freaks

Hot!ss80.c:765:: warning: (753) undefined shift (32 bits)

Author
AndersG
Super Member
  • Total Posts : 241
  • Reward points : 0
  • Joined: 2008/08/05 04:51:24
  • Location: 0
  • Status: offline
2020/11/30 01:58:58 (permalink)
0

ss80.c:765:: warning: (753) undefined shift (32 bits)

While we are on the topic of compiler warnings. This code generates the above message:
   SS80Disk[Unit].Vector = SS80Disk[Unit].Address[2] * 0x100000000L + SS80Disk[Unit].Address[3] 
                    * 0x1000000L + SS80Disk[Unit].Address[4] * 0x10000L + SS80Disk[Unit].Address[5] * 0x100L;

 
Where Vector is a DWORD, di I guess I am creating an overflow here, but XC8 has no larger datatype. But then again might I be able to live with a 4Gb limit..
#1

15 Replies Related Threads

    ric
    Super Member
    • Total Posts : 29435
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: ss80.c:765:: warning: (753) undefined shift (32 bits) 2020/11/30 02:21:45 (permalink)
    -1 (1)
    What does the definition of SS80Disk look like?
     
     

    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!
    #2
    JPortici
    Super Member
    • Total Posts : 1239
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: ss80.c:765:: warning: (753) undefined shift (32 bits) 2020/11/30 02:51:07 (permalink)
    +1 (1)
    In C99 mode, for PIC18 and PIC16 with enchanced CPU long long is 64 bit.
    (Last week i had some configuration screwups, in which a project that was supposed to be in C99 actually wasn't. took me a while to figure out)
    #3
    moser
    Super Member
    • Total Posts : 603
    • Reward points : 0
    • Joined: 2015/06/16 02:53:47
    • Location: Germany
    • Status: offline
    Re: ss80.c:765:: warning: (753) undefined shift (32 bits) 2020/11/30 02:58:15 (permalink)
    0
    Always provide all declarations! You only told us about vector. But what is "Address" and what is "Unit"? This stuff matters! And SS80Disk might also be helpful.
     
    Note, that 0x100000000L is 33 bit, which results in 64 bit. If the compiler tries to use that with a 32 bit variable, it won't work. Read 5.3.7.1 "Integral Constants" from the compiler manual. I think you might need to cast the SS80Disk[Unit].Address[whatever] to 64 bit (signed/unsigned) long long.
     
    I have never worked with XC8. However, the manual says something about that a signed/unsigned long long can be either 32 or 64 bit. Make sure you have that right:
    The long long types are 64-bit C99 standard types when building for PIC18 or Enhanced Mid-range devices, but this implementation limits their size to only 32 bits for projects conforming to the C90 Standard or any project targeting any other device.

    #4
    1and0
    Access is Denied
    • Total Posts : 11747
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: ss80.c:765:: warning: (753) undefined shift (32 bits) 2020/11/30 03:52:22 (permalink)
    -1 (1)
    moser
    Note, that 0x100000000L is 33 bit, which results in 64 bit. If the compiler tries to use that with a 32 bit variable, it won't work. Read 5.3.7.1 "Integral Constants" from the compiler manual. I think you might need to cast the SS80Disk[Unit].Address[whatever] to 64 bit (signed/unsigned) long long.

    It will work with C99 mode, but not with C90 mode. There's no need to cast Address[] since the integral constant that it multiples with is already a long long type.  From the look of OP's statement, Address[] is 8-bit width.
    #5
    AndersG
    Super Member
    • Total Posts : 241
    • Reward points : 0
    • Joined: 2008/08/05 04:51:24
    • Location: 0
    • Status: offline
    Re: ss80.c:765:: warning: (753) undefined shift (32 bits) 2020/11/30 03:52:55 (permalink)
    0
    struct {
    BYTE Volume;
    BYTE Address[6]; // SS80 Address, Address[5] = LSB. In blocks
    DWORD Vector; // Vector, ie file position, in blocks
    DWORD Maxvector; // Maximum file position, used for bounds checking. Initialised by SS80_init.
    LengthType Length; // Length, in blocks
    BYTE Errors; // Error byte
    } SS80Disk[MAXDISK+1];

     
    So, does XC8 support long long now? In c99 mode?
     
     
    #6
    1and0
    Access is Denied
    • Total Posts : 11747
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: ss80.c:765:: warning: (753) undefined shift (32 bits) 2020/11/30 03:55:35 (permalink)
    -1 (1)
    AndersG
    While we are on the topic of compiler warnings. This code generates the above message:
       SS80Disk[Unit].Vector = SS80Disk[Unit].Address[2] * 0x100000000L + SS80Disk[Unit].Address[3] 
                        * 0x1000000L + SS80Disk[Unit].Address[4] * 0x10000L + SS80Disk[Unit].Address[5] * 0x100L;

     
    Where Vector is a DWORD, di I guess I am creating an overflow here, but XC8 has no larger datatype. But then again might I be able to live with a 4Gb limit..

    What type is DWORD? How many bits is it?
     
    For your statement to work, Vector must be a 64-bit type supported in C99 mode. Largest integer type in C90 mode of the XC8 compiler is only 32-bit. So make sure you select C99 mode.
    #7
    1and0
    Access is Denied
    • Total Posts : 11747
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: ss80.c:765:: warning: (753) undefined shift (32 bits) 2020/11/30 03:57:37 (permalink)
    -1 (1)
    AndersG
    struct {
    BYTE Volume;
    BYTE Address[6]; // SS80 Address, Address[5] = LSB. In blocks
    DWORD Vector; // Vector, ie file position, in blocks
    DWORD Maxvector; // Maximum file position, used for bounds checking. Initialised by SS80_init.
    LengthType Length; // Length, in blocks
    BYTE Errors; // Error byte
    } SS80Disk[MAXDISK+1];

     
    So, does XC8 support long long now? In c99 mode?

    The long long type is 64-bit in C99 mode and 32-bit in C90 mode.  May I suggest you to use the types defined in <stdint.h>.
    #8
    andersm
    Super Member
    • Total Posts : 2867
    • Reward points : 0
    • Joined: 2012/10/07 14:57:44
    • Location: 0
    • Status: offline
    Re: ss80.c:765:: warning: (753) undefined shift (32 bits) 2020/11/30 05:29:30 (permalink)
    +1 (1)
    I assume the reason for the slightly confusing error message is that the compiler converts the multiplications into left shifts, but since the result can't be represented in the result type, it invokes undefined behavior.
    #9
    AndersG
    Super Member
    • Total Posts : 241
    • Reward points : 0
    • Joined: 2008/08/05 04:51:24
    • Location: 0
    • Status: offline
    Re: ss80.c:765:: warning: (753) undefined shift (32 bits) 2020/11/30 05:30:28 (permalink)
    0
    Those are from FATFs, but I see that the latest version of that has code to handle C99 (below). I will try enavling C99 and see what happens, but this is not a big issue for me. I do not expect disk image files larger than 4Gb here in the near future. The code is for a disk emulator for instrument and computers from the 1980's :)
     
    Also: The code started out 10 years ago on MPLAB and that compiler so there may be artefacts from that.
     
    Thanks al lot for the explanations and pointers (pun intended)
     
    /* Integer types used for FatFs API */

    #if defined(_WIN32) /* Main development platform */
    #define FF_INTDEF 2
    #include <windows.h>
    typedef unsigned __int64 QWORD;
    #elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__cplusplus) /* C99 or later */
    #define FF_INTDEF 2
    #include <stdint.h>
    typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
    typedef unsigned char BYTE; /* char must be 8-bit */
    typedef uint16_t WORD; /* 16-bit unsigned integer */
    typedef uint32_t DWORD; /* 32-bit unsigned integer */
    typedef uint64_t QWORD; /* 64-bit unsigned integer */
    typedef WORD WCHAR; /* UTF-16 character type */
    #else /* Earlier than C99 */
    #define FF_INTDEF 1
    typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
    typedef unsigned char BYTE; /* char must be 8-bit */
    typedef unsigned short WORD; /* 16-bit unsigned integer */
    typedef unsigned long DWORD; /* 32-bit unsigned integer */
    typedef WORD WCHAR; /* UTF-16 character type */
    #endiftypedef unsigned long DWORD; /* 32-bit unsigned integer */

     
     
     
    #10
    AndersG
    Super Member
    • Total Posts : 241
    • Reward points : 0
    • Joined: 2008/08/05 04:51:24
    • Location: 0
    • Status: offline
    Re: ss80.c:765:: warning: (753) undefined shift (32 bits) 2020/11/30 05:45:56 (permalink)
    0
    Odd.. I have it set to C99 in  the project properties, but for some reason does not defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) fire?
    #11
    1and0
    Access is Denied
    • Total Posts : 11747
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: ss80.c:765:: warning: (753) undefined shift (32 bits) 2020/11/30 06:17:35 (permalink)
    0 (2)
    AndersG
    Odd.. I have it set to C99 in  the project properties, but for some reason does not defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) fire?

    XC8 does not define those macros.
     
    AndersG
    Also: The code started out 10 years ago on MPLAB and that compiler so there may be artefacts from that.
     
    Thanks al lot for the explanations and pointers (pun intended)
     
    [code]
    typedef unsigned long DWORD; /* 32-bit unsigned integer */

    XC8 is less than 9 years old, and its C99 mode is less than 3 years. Your DWORD is only 32 bits wide.
    post edited by 1and0 - 2020/11/30 06:19:36
    #12
    AndersG
    Super Member
    • Total Posts : 241
    • Reward points : 0
    • Joined: 2008/08/05 04:51:24
    • Location: 0
    • Status: offline
    Re: ss80.c:765:: warning: (753) undefined shift (32 bits) 2020/11/30 06:52:15 (permalink)
    +1 (1)
    XC8 does not define those macros.
     
    Thought so. Any idea what it defines when in C99 mode?
     
    Edit: Better define my own, I guess
    post edited by AndersG - 2020/11/30 07:05:21
    #13
    AndersG
    Super Member
    • Total Posts : 241
    • Reward points : 0
    • Joined: 2008/08/05 04:51:24
    • Location: 0
    • Status: offline
    Re: ss80.c:765:: warning: (753) undefined shift (32 bits) 2020/11/30 07:31:49 (permalink)
    0
    I am still a bit confused... You say that it is supported, but the manual says:
    unsigned long long 32 Unsigned integer? Manual out of date?
     
    Anyway, I should be able to change "Vector" from DWORD to QWORD then?
     
    Edit: Did so in the structure, but kept the actual pointer when calling FATFs as 32-bit. To support larger disks, I would have to enable EXFAT and I think I will cross that bridge later.
    post edited by AndersG - 2020/11/30 07:57:46
    #14
    ric
    Super Member
    • Total Posts : 29435
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: ss80.c:765:: warning: (753) undefined shift (32 bits) 2020/11/30 12:27:35 (permalink)
    0 (2)
    AndersG
    I am still a bit confused... You say that it is supported, but the manual says:
    unsigned long long 32 Unsigned integer? Manual out of date?
     

    WHICH manual.
    There are two manuals in the docs folder, one for each mode.
    C90: MPLAB_XC8_C_Compiler_Legacy_User_Guide.pdf
    C99: MPLAB_XC8_C_Compiler_User_Guide_for_PIC.pdf
     
     
     

    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!
    #15
    AndersG
    Super Member
    • Total Posts : 241
    • Reward points : 0
    • Joined: 2008/08/05 04:51:24
    • Location: 0
    • Status: offline
    Re: ss80.c:765:: warning: (753) undefined shift (32 bits) 2020/12/01 06:46:46 (permalink)
    0
    Ah! Thanks!
    #16
    Jump to:
    © 2021 APG vNext Commercial Version 4.5