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

error C258:mspace illegal in struct/union

Hi all
i want to read RTC time parameters.
RTC is treated as one of memory location,it gets enabled when parameters are refered.
following where the codes:

struct tm{
unsigned char xdata second  _at_(0xe000);
unsigned char xdata minute  _at_(0xe002);
unsigned char xdata hour    _at_(0xe004);
};

void main()
{
 struct tm time;
 printf("seconds %x",time.second)
 ...
}
On compiling above code compiler gives following error:
error C258:mspace has illegal in struct/union.

but if code in struct are modified as follows:
struct tm{
unsigned char second _at_(0xe000);
}
Code compiles without any error but RTC was not getting enabled by
addr-decod logic even on disabling internal xram from AUXR.

but if my codes are as follows than things work perfect:

xdata unsigned char second  _at_(0xe000);
xdata unsigned char minute  _at_(0xe002);
xdata unsigned char hour    _at_(0xe004);

void main()
{
  printf("\nseconds %x",second);
  printf("\nminutes %x",minutes);
  printf("\nhours   %x",hour);
}

1)what is wrong with the defn in struct ?
2)i cannot just define struct as xdata because
addr-decoding logic should enable RTC when required,
so how can i declare struct variable so that no error is generated and RTC is enabled ?

3)what if i try to define more than one struct var for above case ?
eg
 struct tm{
 unsigned char xdata second  _at_(0xe000);
 unsigned char xdata minute  _at_(0xe002);
 unsigned char xdata hour    _at_(0xe004);
 };

 void main()
 {
  struct tm time1,time2;
  ......
 

will var in time1 and time2 be placed in same location ?

Regards
Naresh

Parents
  • What you need is:

    struct tm
    {
    	unsigned char second;
    	unsigned char res1;
    	unsigned char minute;
    	unsigned char res2;
    	unsigned char hour;
    };
    
    struct tm xdata time _at_ 0xe000; 	// time starts at 0xe000 !!
    
    void main()
    {
    }
    
    You can specifiy addresses for variables and structures/unions - not for structure elements.
    res1 and res2 are only for filling the gaps.

Reply
  • What you need is:

    struct tm
    {
    	unsigned char second;
    	unsigned char res1;
    	unsigned char minute;
    	unsigned char res2;
    	unsigned char hour;
    };
    
    struct tm xdata time _at_ 0xe000; 	// time starts at 0xe000 !!
    
    void main()
    {
    }
    
    You can specifiy addresses for variables and structures/unions - not for structure elements.
    res1 and res2 are only for filling the gaps.

Children
  • "You can specifiy addresses for variables and structures/unions - not for structure elements."

    Yes, I was surprised that he seemed to be suggesting that the compiler accepted _at_ within a structure definition!!??

    Does it really????


  • "Yes, I was surprised that he seemed to be suggesting that the compiler accepted _at_ within a structure definition!!??

    Does it really????"


    The compiler ignores the _at_ statement applied to structure elements! There is no compile error - I have tried it with V7.06a.

    The compiler calculates the addresses of structure elements from the beginning of the structure - and this is not 0xe000

  • "Yes, I was surprised that he seemed to be suggesting that the compiler accepted _at_ within a structure definition!!??"

    I assumed that if it compiled without warning...

    Silly me.

    Stefan

  • "I assumed that if it compiled without warning..."

    Yes sounds like a bug to me - the user should at least be warned!?

  • Thanks for reply.
    with following code:

    struct tm
    {
    	unsigned char second;
    	unsigned char res1;
    	unsigned char minute;
    	unsigned char res2;
    	unsigned char hour;
    };
    struct tm xdata time _at_ 0xe000; 	// time starts at 0xe000 !!
    
    void main()
    {
    }
    

    will compiler assign following addrress for struct elements ?

    second --> 0xe000
    res1 --> 0xe0001
    minute --> 0xe002
    res2 --> 0xe0003
    hour --> 0xe004


    what if i define:
    struct tm xdata time1 _at_ 0xe000;
    struct tm xdata time2 _at_ 0xe000;
    will the elements of both struct time1 and time2 refer same location ?
    changes made in elements of time1,will disturb elements of time2 ?


    Regards
    Naresh

  • "will compiler assign following addrress for struct elements?"

    I think you need to go back to your 'C' textbook and read-up on the way structures work.

    what if i define:

    struct tm xdata time1 _at_ 0xe000;
    struct tm xdata time2 _at_ 0xe000;

    You have declared two different variables at the same memory address - this will probably give you a Linker error!

    Why would you want to do this?