• AVR Freaks

sizeof(double) is 4 octets

Author
Emcy
Super Member
  • Total Posts : 569
  • Reward points : 0
  • Joined: 2008/01/09 03:37:06
  • Location: 0
  • Status: offline
2012/02/10 03:17:45 (permalink)
0

sizeof(double) is 4 octets

Hello,
 
In the PIC32 Compiler User's guide, the type 'double' is 64 bits but in my prgramm, it is 32 bits  :
     printf("%lu\r\n", sizeof(double));     // => print "4"     

 
=> is it normal ? double min size should be 64 bits (C99 standard), isn't it ? 
=> there is a problem with my project ?
 
#1

10 Replies Related Threads

    dlindbergh
    Super Member
    • Total Posts : 478
    • Reward points : 0
    • Joined: 2006/09/11 18:17:11
    • Location: Boston USA
    • Status: offline
    Re:sizeof(double) is 4 octets 2012/02/10 08:15:18 (permalink)
    0
    They changed the default size for double from 64 bits to 32 bits in recent versions of the compiler.

    There's a switch you can use to change it back.

    See the release notes on the compiler.

    [And I agree - they really need to update the C32 user's manual!]
    #2
    concertinaman
    Bug Sorter
    • Total Posts : 250
    • Reward points : 0
    • Joined: 2007/06/14 05:56:58
    • Location: UK
    • Status: offline
    Re:sizeof(double) is 4 octets 2012/02/10 08:27:11 (permalink)
    0
    use long double for 64 bits.
    #3
    aschen0866
    Super Member
    • Total Posts : 4504
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    Re:sizeof(double) is 4 octets 2012/02/10 10:24:00 (permalink)
    0
    Not sure what documentation you guys are referring to, but the size of long, signed or unsigned, has always been 32-bit since v1.00...
    #4
    concertinaman
    Bug Sorter
    • Total Posts : 250
    • Reward points : 0
    • Joined: 2007/06/14 05:56:58
    • Location: UK
    • Status: offline
    Re:sizeof(double) is 4 octets 2012/02/10 11:14:47 (permalink)
    0
    aschen0866

    Not sure what documentation you guys are referring to, but the size of long, signed or unsigned, has always been 32-bit since v1.00...


    1.5.4 Floating-Point Representation
    DS51686B page 8

    That's MPLAB C32 User Guide.pdf as shipped with V2.02

     
    post edited by concertinaman - 2012/02/10 11:18:19
    #5
    aschen0866
    Super Member
    • Total Posts : 4504
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    Re:sizeof(double) is 4 octets 2012/02/10 11:35:33 (permalink)
    0
    Somehow I thought the OP was asking about the size of long...I'd better shut up since I can't even read straight.
    #6
    Emcy
    Super Member
    • Total Posts : 569
    • Reward points : 0
    • Joined: 2008/01/09 03:37:06
    • Location: 0
    • Status: offline
    Re:sizeof(double) is 4 octets 2012/02/13 04:00:50 (permalink)
    0
    ok, thanks
    #7
    tmig
    Senior Member
    • Total Posts : 163
    • Reward points : 0
    • Joined: 2007/04/18 09:34:33
    • Location: cape cod
    • Status: offline
    Re:sizeof(double) is 4 octets 2012/02/15 09:51:50 (permalink)
    0
     
    I assume you mean doubles as floating point. I recently migrated to 2.x of the compiler and was hit by this. I tried long double but it didn't appear to work correctly - at least the debugger didn't seem to like it and the output wasn't correct. I then used the compiler directive -fno-short-double and the debugger understood, and the fp numbers were interpreted correctly, but at the same time sscanf broke - it now only wants to take doubles for floating point arguments. I am still looking to see if it broke any other floating point math functions. Somebody at Microchip needs to document this better. If anyone has any further information or a better way to handle this please post!
     
    Thanks
     
    Tmig
    post edited by tmig - 2012/02/15 09:55:33
    #8
    Aiden.Morrison
    Super Member
    • Total Posts : 729
    • Reward points : 0
    • Joined: 2005/02/25 11:18:31
    • Location: Canada
    • Status: offline
    Re:sizeof(double) is 4 octets 2012/02/20 09:38:17 (permalink)
    0
    This seems like a dangerous change to the compiler...

    My understanding of the term double refers to 'double precision floating point' which is 64 bits.

    Could someone from Microchip comment on where I can find a 'single precision' floating point variable that is 16 bits?
    #9
    dlindbergh
    Super Member
    • Total Posts : 478
    • Reward points : 0
    • Joined: 2006/09/11 18:17:11
    • Location: Boston USA
    • Status: offline
    Re:sizeof(double) is 4 octets 2012/03/03 08:23:56 (permalink)
    0
    Aiden.Morrison My understanding of the term double refers to 'double precision floating point' which is 64 bits.

    Could someone from Microchip comment on where I can find a 'single precision' floating point variable that is 16 bits?
     


    Single precision float ("float" in V1.x) is 32 bits.


    Double precision float ("double" in v1.x) is 64 bits.


    16 bit floats are not supported in C32.  (C18 does have that data type....)


    #10
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re:sizeof(double) is 4 octets 2012/03/04 08:16:16 (permalink)
    0
    dlindbergh


    16 bit floats are not supported in C32.  (C18 does have that data type....)


    Argh, I did not ever see that... ! Smile

    GENOVA :D :D ! GODO
    #11
    Jump to:
    © 2019 APG vNext Commercial Version 4.5