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

RAM Space

I could not find an explanation for an observation given below.

1)When I declared bits like
bit AM,fg_chat,pumpoff=0;pumpon=0,mode=0;
bit PMP_flag = 1,buzzer=0,pumpon_flag=0;
bit xmitempty,flash1,response_received=0,response_delayed=0,sms_flag;
bit oht_red,oht_rg,glr_red,glr_rg;

my program data size was 74.3 bytes and code size 2179(there are many other variables also)
but when I declared like
bit AM,fg_chat,pumpoff=0;pumpon=0,mode=0, PMP_flag = 1,buzzer=0,pumpon_flag=0, xmitempty,flash1,response_received=0,response_delayed=0,sms_flag, oht_red,oht_rg,glr_red,glr_rg;
the data size increased to 96.7 bytes and code size 2387.
I use 89S52 uC.

Why this happens? What is difference between these?

Parents
  • That's one reason why it's generally best not to have multiple declarations in a single statement!

    There are also a number of other pitfalls; eg

    char* p1, p2; // does not define two pointers!
    

    See: c-faq.com/.../charstarws.html

    I would also encourage you to make it a habit to comment every definition; eg,

    bit xmitempty;             // Explain the purpose of this variable
    bit flash1;                // Explain the purpose of this variable
    bit response_received=0;   // Explain the purpose of this variable
    bit response_delayed =0;   // Explain the purpose of this variable
    bit sms_flag;              // Explain the purpose of this variable
    

    So - lots of reasons not to have multiple declarations/definitions in a single statement!

Reply
  • That's one reason why it's generally best not to have multiple declarations in a single statement!

    There are also a number of other pitfalls; eg

    char* p1, p2; // does not define two pointers!
    

    See: c-faq.com/.../charstarws.html

    I would also encourage you to make it a habit to comment every definition; eg,

    bit xmitempty;             // Explain the purpose of this variable
    bit flash1;                // Explain the purpose of this variable
    bit response_received=0;   // Explain the purpose of this variable
    bit response_delayed =0;   // Explain the purpose of this variable
    bit sms_flag;              // Explain the purpose of this variable
    

    So - lots of reasons not to have multiple declarations/definitions in a single statement!

Children