Unsigned chars in message queues

Is there a way to get message queues (mq_send(…), mq_receive(…),
etc)
to accept unsigned char* in stead on char* ??

-Arve

cast it

unsigned char *p;

mq_send ( …, (const char *)p, … )

“Arve Slenes” <arve@datarespons.no> wrote in message
news:3B28979B.599231BC@datarespons.no

Is there a way to get message queues (mq_send(…), mq_receive(…),
etc)
to accept unsigned char* in stead on char* ??

-Arve

…is giving me troubles when using GNU C++ compiler and C++ casts,
but I solved it myself by using write(…) and read(…) instead.
These takes a void* as argument. :slight_smile:

-Arve

Mario Charest wrote:

cast it

unsigned char *p;

mq_send ( …, (const char *)p, … )

“Arve Slenes” <> arve@datarespons.no> > wrote in message
news:> 3B28979B.599231BC@datarespons.no> …
Is there a way to get message queues (mq_send(…), mq_receive(…),
etc)
to accept unsigned char* in stead on char* ??

-Arve

Arve Slenes <arve@datarespons.no> wrote:

…is giving me troubles when using GNU C++ compiler and C++ casts,
but I solved it myself by using write(…) and read(…) instead.
These takes a void* as argument. > :slight_smile:

That will work – but you do lose the ability to assign a priority to
your messages or get the priority for the messages you are receiving.

(When you write(), all the messages sent that way will have priority
0, the lowest priority.)

-David

QNX Training Services
dagibbs@qnx.com

“Arve Slenes” <arve@datarespons.no> wrote in message
news:3B28C53F.5D1A0D39@datarespons.no

…is giving me troubles when using GNU C++ compiler and C++ casts,

You are probably casting it wrong. Can you post some code.

but I solved it myself by using write(…) and read(…) instead.
These takes a void* as argument. > :slight_smile:

Talk about taking the long road :wink:)

-Arve

Mario Charest wrote:

cast it

unsigned char *p;

mq_send ( …, (const char *)p, … )

“Arve Slenes” <> arve@datarespons.no> > wrote in message
news:> 3B28979B.599231BC@datarespons.no> …
Is there a way to get message queues (mq_send(…), mq_receive(…),
etc)
to accept unsigned char* in stead on char* ??

-Arve

unsigned char buffer[rdMqAttr.mq_msgsize];
unsigned char * ptmpBuff = &buffer[0];
unsigned int priority = 0;
size_t size;

//This is how I did it with write (priority is no need at the moment)
size = read(rdMessageQueue, ptmpBuff, rdMqAttr.mq_msgsize);

//This is how I now do it, using a reinterpret_cast
size = mq_receive(rdMessageQueue, reinterpret_cast<char*>(ptmpBuff),
rdMqAttr.mq_msgsize, &priority);

This works fine!!

  • Arve


    Mario Charest wrote:

“Arve Slenes” <> arve@datarespons.no> > wrote in message
news:> 3B28C53F.5D1A0D39@datarespons.no> …
…is giving me troubles when using GNU C++ compiler and C++ casts,

You are probably casting it wrong. Can you post some code.

but I solved it myself by using write(…) and read(…) instead.
These takes a void* as argument. > :slight_smile:

Talk about taking the long road > :wink:> )


-Arve

Mario Charest wrote:

cast it

unsigned char *p;

mq_send ( …, (const char *)p, … )

“Arve Slenes” <> arve@datarespons.no> > wrote in message
news:> 3B28979B.599231BC@datarespons.no> …
Is there a way to get message queues (mq_send(…), mq_receive(…),
etc)
to accept unsigned char* in stead on char* ??

-Arve

“Arve Slenes” <arve@datarespons.no> wrote in message news:3B2F5F0B.A0379B4B@datarespons.no
unsigned char buffer[rdMqAttr.mq_msgsize];
unsigned char * ptmpBuff = &buffer[0];
unsigned int priority = 0;
size_t size;
//This is how I did it with write (priority is no need at the moment)
size = read(rdMessageQueue, ptmpBuff, rdMqAttr.mq_msgsize);

//This is how I now do it, using a reinterpret_cast
size = mq_receive(rdMessageQueue, reinterpret_cast<char*>(ptmpBuff), rdMqAttr.mq_msgsize, &priority);



What is a reinterpret_cast?

size = mq_receive(rdMessageQueue, (char*)ptmpBuff, rdMqAttr.mq_msgsize, &priority);

should work just fine.





This works fine!!

  • Arve


    Mario Charest wrote:

“Arve Slenes” <arve@datarespons.no> wrote in message
news:3B28C53F.5D1A0D39@datarespons.no

…is giving me troubles when using GNU C++ compiler and C++ casts,
You are probably casting it wrong. Can you post some code.



but I solved it myself by using write(…) and read(…) instead.
These takes a void* as argument. > :slight_smile:

Talk about taking the long road :wink:)

-Arve

Mario Charest wrote:

cast it

unsigned char *p;

mq_send ( …, (const char *)p, … )

“Arve Slenes” <> arve@datarespons.no> > wrote in message
news:> 3B28979B.599231BC@datarespons.no> …
Is there a way to get message queues (mq_send(…), mq_receive(…),
etc)
to accept unsigned char* in stead on char* ??

-Arve

Yep! (char*) works just fine, but I’m programming in C++, and using one
of static_cast, dynamic_cast, const_cast, or reinterpret_cast is the C++
way of doing casts. Syntax being as follows:

type_of_cast(what to cast from)

I think this is the prefered way of casting in C++. The C cast still
works, but it are more prone to errors. This is at least what Scott
Meyers says in his book Effective C++, and also what Bjarne Sostrup
says…

A reinterpret_cast is engineered for casts that yield
implementation-dependent results
This is not often used however.

const_cast used to cast away the constness of objects and pointers

dynamic_cast is used to perform “safe downcasting”

static_cast is a catch-all cast. This is the closest to the C-style
casts. (It does not work in this case however, and I think
reinterpret_cast is the one to use)

-Arve

Mario Charest wrote:

“Arve Slenes” <> arve@datarespons.no> > wrote in message
news:3B2F5F0B.A0379B4B@datarespons.no…unsigned char
buffer[rdMqAttr.mq_msgsize];
unsigned char * ptmpBuff = &buffer[0];
unsigned int priority = 0;
size_t size;

//This is how I did it with write (priority is no need at
the moment)
size = read(rdMessageQueue, ptmpBuff, rdMqAttr.mq_msgsize);

//This is how I now do it, using a reinterpret_cast
size = mq_receive(rdMessageQueue,
reinterpret_cast<char*>(ptmpBuff), rdMqAttr.mq_msgsize,
&priority);



What is a reinterpret_cast?

size = mq_receive(rdMessageQueue, (char*)ptmpBuff,
rdMqAttr.mq_msgsize, &priority);

should work just fine.





This works fine!!

  • Arve


    Mario Charest wrote:

“Arve Slenes” <> arve@datarespons.no> > wrote in message
news:> 3B28C53F.5D1A0D39@datarespons.no> …
…is giving me troubles when using GNU C++ compiler and
C++ casts,

You are probably casting it wrong. Can you post some
code.

but I solved it myself by using write(…) and read(…)
instead.
These takes a void* as argument. > :slight_smile:

Talk about taking the long road > :wink:> )


-Arve

Mario Charest wrote:

cast it

unsigned char *p;

mq_send ( …, (const char *)p, … )

“Arve Slenes” <> arve@datarespons.no> > wrote in message
news:> 3B28979B.599231BC@datarespons.no> …
Is there a way to get message queues (mq_send(…),
mq_receive(…),
etc)
to accept unsigned char* in stead on char* ??

-Arve