OS_Q_Create Documentation

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • OS_Q_Create Documentation

    Hello,

    I got a question regarding the documentation for OS_Q_Create (manual 3.82f).
    For the parameter pData it says: "Pointer to a memory area used as data buffer for the queue."
    But the example is as this:

    C Source Code

    1. #define MEMORY_QSIZE 10000;
    2. static OS_Q _MemoryQ;
    3. static char _acMemQBuffer[MEMORY_QSIZE];
    4. void MEMORY_Init(void) {
    5. OS_Q_Create(&_MemoryQ, &_acMemQBuffer, sizeof(_acMemQBuffer));


    The '&' in front of '_acMemQBuffer' (line 5) puzzles me: that would be a pointer to a pointer to a memory area. Or am I wrong?

    Thanx, Arne
  • Hello Arne,

    you are right, there is a mistake in the sample code.
    The corrected code is:

    C Source Code

    1. OS_Q_Create(&_MemoryQ, _acMemQBuffer, sizeof(_acMemQBuffer));


    I will correct the embOS manual, thanks for the hint.

    Regards,
    Til
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Arne wrote:

    The '&' in front of '_acMemQBuffer' (line 5) puzzles me: that would be a pointer to a pointer to a memory area. Or am I wrong?
    An array name often (nearly always) evaluates (or 'decays') to a pointer to the first element of the array, but the array is not itself a pointer. Taking the address of the array (&_acMemQBuffer) also results in a pointer to the array (the pointer is of a different type, though), not a pointer to a pointer. Both expressions will be pointers with the same value, just somewhat different types.

    The expression _acMemQBuffer is a pointer with type char*.

    The expression &_acMemQBuffer is a pointer with type char(*)[10000] (ie., pointer to an array of 10000 char).

    Both pointers have the same 'numeric' value (they both point to the same address).

    Since the 2nd parameter of OS_Q_Create() is a void* there's no complaint about the pointer's type by the compiler (any pointer can convert implicitly to a void*).

    I think there's no error in the original example.