Friday, December 15th 2017, 7:00pm 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.

Arne

Beginner

Date of registration: Jul 29th 2010

Posts: 5

1

Thursday, July 29th 2010, 10:29am

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

1
2
3
4
5
#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

SEGGER - Til

Super Moderator

Date of registration: Nov 14th 2007

Posts: 261

2

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

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


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

Regards,
Til

mwb1100

Beginner

Date of registration: Sep 30th 2009

Posts: 27

3

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