Menu

Casting error while initializing pointers

Help
AmdlSpace
2007-08-22
2013-03-12
  • AmdlSpace

    AmdlSpace - 2007-08-22

    Using SDCC compiler for a C51 simple application,
    for the following two lines variable declarations:

    unsigned int  address;
    unsigned char * mem_ptr;

    I've got the compilation error "127" for the following  instruction line:

    mem_ptr =  (unsigned char * )address;

    The error "127" maps to:
    "non-pointer type cast to generic pointer from type 'unsigned-int to type unsigned-char generic*"

    NOW THE QUESTION: is there anybody of you who can kindly suggest me an alternative and compilable way to initialize the "mem_ptr" pointer variable with the content of the "address" one?

    Thank you in advance!

     
    • Raphael Neider

      Raphael Neider - 2007-08-22

      In which memory space is the object pointed to by address in?

      Use
      1. mem_ptr = (__data unsigned char *) address;
      2. mem_ptr = (__xdata unsigned char *) address;
      3. mem_ptr = (__code unsigned char *) address;
      4. ...

      or (untested) declare mem_ptr as a pointer to one of these spaces, like
      1. __data unsigned char *mem_ptr;
      2. __xdata unsigned char *mem_ptr;
      3. __code unsigned char *mem_ptr;
      4. ...

      Otherwise SDCC would have to guess the memory space and its according TAG (most significant bits ot the generic pointer's value).

      HTH,
      Raphael

       

Log in to post a comment.

MongoDB Logo MongoDB