# passing a queuehandle\_t pointer?

**URL:** <https://forums.freertos.org/t/passing-a-queuehandle-t-pointer/7302>\
**Category:** Kernel\
**Created:** [July 5, 2018, 11:48am UTC](https://forums.freertos.org/t/passing-a-queuehandle-t-pointer/7302 "2018-07-05T11:48:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [July 5, 2018, 11:48am UTC](https://forums.freertos.org/t/passing-a-queuehandle-t-pointer/7302/1 "2018-07-05T11:48:29Z")

</div>

**[nigel-m](https://sourceforge.net/u/nigel-m/)** wrote on [Thursday, July 05, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/9f440984/#1901):

I’m trying to create a queue to communicate between 2 tasks, But passing a pointer to a task seems to crash it.

The following code seems to work fine.

```auto
QueueHandle_t queue = xQueueCreate(10, sizeof(int);
if( uxQueueMessagesWaiting(queue) ) {
    // a message
} else {
    // no message
}

```

But having a pointer seems to let my program crash.

```auto
QueueHandle_t queue = xQueueCreate(10, sizeof(int);
QueueHandle_t *pqueue = &queue;
if( uxQueueMessagesWaiting(pqueue) ) {
    // a message
} else {
    // no message
}

```

which is the same as passing it to a task using pvparameters.

```auto
	void Thread(void *pvParameters)
	{
QueueHandle_t *handle = (QueueHandle_t*)pvParameters;
if( uxQueueMessagesWaiting(handle) ) {

```

What am i doing wrong, comparing my code to examples I dont see any strange difference.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [July 5, 2018, 5:33pm UTC](https://forums.freertos.org/t/passing-a-queuehandle-t-pointer/7302/2 "2018-07-05T17:33:39Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, July 05, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/9f440984/#1901/2a05):

> QueueHandle\_t queue = xQueueCreate(10, sizeof(int);  
> if( uxQueueMessagesWaiting(queue) ) {  
> // a message  
> } else {  
> // no message  
> }

In this case, the type of the parameter you are passing to  
uxQueueMessagesWaiting() is a QueueHandle\_t, which is correct.

> But having a pointer seems to let my program crash.
> 
> QueueHandle\_t queue = xQueueCreate(10, sizeof(int);  
> QueueHandle\_t \*pqueue = &queue;  
> if( uxQueueMessagesWaiting(pqueue) ) {  
> // a message  
> } else {  
> // no message  
> }

In this case, the type of the parameter you are passing to  
uxQueueMessagesWaiting() is a pointer to a QueueHandle\_t, which is not  
correct.

> which is the same as passing it to a task using pvparameters.

If you want to pass a QueueHandle\_t into another task using the task  
parameter then pass it directly, as a value. For example:

xTaskCreate( a, b, c, ( void \* ) queue, x, y, z );

Then just cast it back to a QueueHandle\_t within the created task.

Alternatively you could pass a pointer to the queue, then deference the  
pointer at the other end to get back to the queue, but that is not  
necessary.

[this is a C question really]

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [July 5, 2018, 6:43pm UTC](https://forums.freertos.org/t/passing-a-queuehandle-t-pointer/7302/3 "2018-07-05T18:43:55Z")

</div>

**[nigel-m](https://sourceforge.net/u/nigel-m/)** wrote on [Thursday, July 05, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/9f440984/#7bfa):

Doh, I was thinking way to hard on this one.  
Thx for the great answer!
