This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

why can't const array be in

const char anarray[5]={1,3,5,7,9};

The above works well. But occupies a lot of mem.




const char code anarray[5]={1,3,5,7,9};

Compliled and linked without an error prompt. But works bad.

Parents Reply Children
  • Storage Class is a Keil 'C' language extension:
    specifies where an object is to be located; viz, code, data, idata, pdata, or xdata.
    You can specify a Storage Class independently for each identifier in your program.

    Model (or, more precisely, "Memory Model") is a Keil Compiler option. It defines a default Storage Class (and a few other things) for your program; ie, if you don't explicitly state the Storage Class in a definition, the compiler will automatically use the default specified by the Memory Model, viz:
    Small - data;
    Medium - pdata;
    Large - xdata.

    It's all in the C51 User' Guide (C51.pdf), accessible from the 'Books' tab in the uVision Project window.

  • By storage control I meant telling the compiler which of the many 8051 memory spaces. E.g.

    char idata var1;
    char data var2;
    char xdata var3;
    char pdata var4;
    char code var5;

    I've never actually used pdata (paged data where Port 2 acts as a page register of 256 bytes). I don't remember if there are other storage spaces.

    As for models, you had better read up on those. The default memory model for C51 is SMALL, which is all I have ever used (well, once I used LARGE) despite my application size. SMALL places all variables in data/idata by default so I tell C51 to place loop counters in data, arrays and structs in idata or xdata, and const vars. in code.

    Small also has some other efficiencies that benefit code running on the 8051. Read up the differences between the models.

    - Mark