Menu

#1118 gen.c assumes "sizeof(float) == sizeof(long)"

closed-fixed
5
2013-05-25
2006-05-12
Anonymous
No

When trying to compile code for the PIC16F864 on a
debian x86_64 host, I get

sdcc: gen.c:9359: bitpatternFromVal: Assertion `sizeof
(float) == sizeof (long)' failed.

A quick look to the corresponding line in the source
code reveals that it makes the illegal assumption that
float and long have the same storage size.

My email: laforge@gnumonks.org

Discussion

  • Raphael Neider

    Raphael Neider - 2006-05-19

    Logged In: YES
    user_id=1115835

    Hmm..., what's the `correct' way to do cast the bitpattern
    of a float into a long?

    float f;
    long l = *(long *)(&f);
    ---
    float f;
    long l = 0;
    memcpy(&l, &f, sizeof( float ) );
    ---
    have two unions, one { double; long } and the other { float,
    long } and select the correct one based on sizeof( double )
    == sizeof( long ) vs. sizeof( float ) == sizeof( long ), and
    emit an error if neither holds?

    Can you verify the result is correct if the assertion is
    simply removed? I cannot due to lack of x86_64 machines ;-)

    Regards,
    Raphael

     
  • Maarten Brock

    Maarten Brock - 2006-05-20

    Logged In: YES
    user_id=888171

    I'd recommend to include stdint.h and use uint32_t instead
    of unsigned long.

     
  • Raphael Neider

    Raphael Neider - 2006-05-20

    Logged In: YES
    user_id=1115835

    Fixed using Maarten's hint in SDCC r4182.

     
  • Raphael Neider

    Raphael Neider - 2006-05-20
    • milestone: --> fixed
    • assigned_to: nobody --> tecodev
    • status: open --> closed-fixed
     
  • Maarten Brock

    Maarten Brock - 2006-05-21

    Logged In: YES
    user_id=888171

    Ok, so I cut myself here. Visual C, which I happen to use,
    does not have the stdint.h header file. Not for VC6 nor
    VC7 nor VC8. Luckily someone already implemented a small
    open source version of it:
    http://www.quantum-leaps.com/downloads/ports.htm#QEP
    There are probably more out there.

     
  • Bernhard Held

    Bernhard Held - 2006-05-22

    Logged In: YES
    user_id=203539

    The "official" target-types are:
    "TYPE_WORD", "TYPE_UWORD", "TYPE_DWORD" and "TYPE_UDWORD" for
    "int", "unsigned int", "long" and "unsigned long". See
    "specifier" in SDCCsymt.h

    These types are evaluated by 'configure' and stored in
    sdccconf.h (there's a sdcc_vc_in.h for VC).

    May be aopLiteral() or aopLiteralLong() in SDCCglue.c is
    doning what you're looking for.

    HTH!

     
  • Maarten Brock

    Maarten Brock - 2006-05-26

    Logged In: YES
    user_id=888171

    Raphael,

    Bernhard is right. Why don't you use aopLiteral()?
    Please have a look at the attached patch.

    Maarten

     
  • Maarten Brock

    Maarten Brock - 2006-05-26

    Remove bitpatternFromVal, use aopLiteral

     

Log in to post a comment.