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

strlen() <-> xstrlen(), xhuge, etc.

Hi all,

Our project uses the HLARGE memory model. I'm trying to run the (received but not very well documented) application from RAM instead of flash by copying it to RAM in the startup.a66 file. And now I'm running into some problems and I'm not sure if it's caused by a lack of C167 knowledge, or lack of application/dependency knowledge. Probably both :-)

My questions:

What is the difference between strlen() and xstrlen() (or x...() functions in general)?

Why wouldn't I be able to use strlen() (which is standard C right?)? What situations require xstrlen() to be used and what would go wrong if you don't?

If you have a regular declared character array:

static const g_u8_typ crc_TEST_STRING[]= "THE,QUICK,BROWN,FOX,0123456789" ;
can you feed it to a function that requires a xhuge pointer? Or does the string have to be declared as xhuge as well, and if so, why?

Thanks,
Joost Leeuwesteijn

Parents
  • What is the difference between strlen() and xstrlen() (or x...() functions in general)?

    The x..() functions work across segment boundaries. For the sake of efficiency (and portability) I would recommend not using them unless necessary.

    Why wouldn't I be able to use strlen() (which is standard C right?)? What situations require xstrlen() to be used and what would go wrong if you don't?

    With HLARGE memory model you can use strlen. You only should use xstrlen if the string is longer tan 64k, in which case you need to declare the string xhuge.

    If you have a regular declared character array
    ...
    can you feed it to a function that requires a xhuge pointer? Or does the string have to be declared as xhuge as well, and if so, why?


    You can pass it as xhuge pointer without declaring it xhuge. If you have the function prototypes present when you compile (and you should), the compiler inserts the necessary code to convert between different pointer types. However, this conversion means extra code executed and it probably is best to keep the memory type declarations of the variables at minimum.

    Sauli

Reply
  • What is the difference between strlen() and xstrlen() (or x...() functions in general)?

    The x..() functions work across segment boundaries. For the sake of efficiency (and portability) I would recommend not using them unless necessary.

    Why wouldn't I be able to use strlen() (which is standard C right?)? What situations require xstrlen() to be used and what would go wrong if you don't?

    With HLARGE memory model you can use strlen. You only should use xstrlen if the string is longer tan 64k, in which case you need to declare the string xhuge.

    If you have a regular declared character array
    ...
    can you feed it to a function that requires a xhuge pointer? Or does the string have to be declared as xhuge as well, and if so, why?


    You can pass it as xhuge pointer without declaring it xhuge. If you have the function prototypes present when you compile (and you should), the compiler inserts the necessary code to convert between different pointer types. However, this conversion means extra code executed and it probably is best to keep the memory type declarations of the variables at minimum.

    Sauli

Children
No data