#529 ignores code sometimes


I found that when an *internal* variable (idata or data)
is declared as "extern" and later declared, the compiler
sometimes ignores a line. Both variables were of
type "unsigned long" and were divided. If you need
more, I can send the entire source code.

function Something() {
extern data long Variable1, Variable2;


more code

data long Variable1, Variable2; // I like to put global
variables by the functions that most need them.
function SomethingElse() {
// Expressions using variable1 and variable 2 do get
compiled here

When Variable1 and Variable2 were moved to xdata, the
lines compiled. The compiler never gave a warning; it
acted like the lines were comment lines and ignored
them when Variable1 and Variable2 were in internal



  • Nobody/Anonymous

    Logged In: NO

    I made a mistake in this bug reporting. The code that gets
    ignored is when I *assign* to an extern data variable that
    hasn't yet been defined in the code. It isn't when it is in the

    void Function() {
    extern data unsigned int Variable1;

    Variable1=expression involving dividing long values; // This
    is where it gets ignored (eliminated as dead code?)


    // More code

    data unsigned int Variable1; // It is defined here in code
    (outside of a function, but after the code shown above)

    As long as the variable does not have forward declaration, it
    works. Forward declaration also works as long as the variable
    is xdata instead of data or idata.


  • Maarten Brock

    Maarten Brock - 2004-03-09

    Logged In: YES

    Isn't this all about the scope of a variable? Is it legal C to
    declare an external variable inside a function definition with
    the actual definition of the variable outside of the function
    block like this?

    void foo(void)
    extern data unsigned int Variable1;
    long x = 1000000;
    long y = 1000;

    Variable1 = x / y;

    data unsigned int Variable1;

    I do consider it a bug though that SDCC doesn't even throw a
    warning on this one.

  • Maarten Brock

    Maarten Brock - 2004-05-06

    Logged In: YES

    Ok, so I looked it up and it's legal. Then I tried to find the
    bug and fix it. Somewhere in the iCode generation the extern
    keyword was forgotten and the variable was treated local
    afterwards. And that resulted in the code being optimized
    away. The fix is in the patches area.


  • Erik Petrich

    Erik Petrich - 2004-05-14
    • milestone: --> fixed
    • status: open --> closed-fixed
  • Erik Petrich

    Erik Petrich - 2004-05-14

    Logged In: YES

    Fixed; see ChangeLog 1.720 for the updated files.
    Thanks to Maarten for solving this bug.


Log in to post a comment.

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

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks