#2031 Incorrect error message

closed-fixed
Ben Shi
Front-end
5
2015-02-25
2012-06-01
Koliada
No

The following code;

unsigned a;
unsigned b = (unsigned) &a;

using: sdcc --model-large --main-return --fomit-frame-pointer --opt-code-size --nostdlib

Generates an error 2: Initializer element is not constant

True for sdcc 2.90 & 3.1.0

Presumably because a pointer is larger than unsigned in large model.

The error message is misleading and should relate the correct cause.

Discussion

  • Koliada

    Koliada - 2012-06-02

    Further to this, the following code does not compile in >all< models;

    unsigned a;
    const unsigned b = (unsigned) &a;

    The only difference is the addition of const to b's data type.

     
  • Ben Shi

    Ben Shi - 2015-02-23

    A solution might be:

    In printIvalType@SDCCglue.c, make a call to printIvalPtr@SDCCglue.c, if list2val() returns a NULL.

    Something like,

    if ( ! ( val = list2val ( ilist ) ) )
    {
    // assuming a warning has been thrown
    val = initPointer (ilist, type);
    if (!val)
    val = constCharVal (0) ;
    else {
    printIvalPtr (sym, type, ilist, oBuf) ;
    return ;
    }
    }

     
  • Ben Shi

    Ben Shi - 2015-02-25
    • status: open --> closed-fixed
    • assigned_to: Ben Shi
    • Category: --> Front-end
     
  • Ben Shi

    Ben Shi - 2015-02-25

    Fixed in reversion #9188.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks