Sunday, March 18th 2018, 2:53pm UTC+1

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to SEGGER Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.



Date of registration: Jul 29th 2010

Posts: 5


Thursday, July 29th 2010, 10:29am

OS_Q_Create Documentation


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/C++ Source code

#define MEMORY_QSIZE 10000;
static OS_Q _MemoryQ;
static char _acMemQBuffer[MEMORY_QSIZE];
void MEMORY_Init(void) {
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


Super Moderator

Date of registration: Nov 14th 2007

Posts: 265


Monday, August 2nd 2010, 11:23am

Hello Arne,

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

C/C++ Source code

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

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




Date of registration: Sep 30th 2009

Posts: 27


Thursday, December 2nd 2010, 11:53pm

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.

Similar threads