Can msgQReceive or msgQSend hold the integer parameter for buffer? - VxWorks

This is a discussion on Can msgQReceive or msgQSend hold the integer parameter for buffer? - VxWorks ; How you doing everyone. Nice to see you. By the vxWorks programming, I wander if I could use a integer variable for a buffer. You know, STATUS msgQSend ( MSG_Q_ID msgQId, /* message queue on which to send */ char ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: Can msgQReceive or msgQSend hold the integer parameter for buffer?

  1. Can msgQReceive or msgQSend hold the integer parameter for buffer?

    How you doing everyone. Nice to see you.
    By the vxWorks programming, I wander if I could use a integer variable
    for a buffer.

    You know,

    STATUS msgQSend
    (
    MSG_Q_ID msgQId, /* message queue on which to send */
    char * buffer, /* message to send */
    UINT nBytes, /* length of message */
    int timeout, /* ticks to wait */
    int priority /* MSG_PRI_NORMAL or MSG_PRI_URGENT */
    );

    And the question is the buffer( char* ) could be a integer variable
    like - int buf-.
    that results in problem with little or big endian things.

    int toBeSent;
    toBeSent = 0x37;
    msgQSend( xxx , &toBeSent , sizeof(int) , xxx , xxx );

    and secondary,

    int received;
    msgQReceive( xxx , &received , xxx , xxx , xxx );

    this received variable could be 0x73 by the CPU??

    By your concern .
    Regards ahtz.


  2. Re: Can msgQReceive or msgQSend hold the integer parameter for buffer?

    Hi

    I don't see why not. You may want to cast the int reference to a char*
    - something like

    msgQSend(msgQId, (char*)(&intToSend), sizeof(intToSend), WAIT_FOREVER,
    MSG_PRI_NORMAL)

    Ought to work...

    /Troels
    ahtz wrote:
    > How you doing everyone. Nice to see you.
    > By the vxWorks programming, I wander if I could use a integer variable
    > for a buffer.
    >
    > You know,
    >
    > STATUS msgQSend
    > (
    > MSG_Q_ID msgQId, /* message queue on which to send */
    > char * buffer, /* message to send */
    > UINT nBytes, /* length of message */
    > int timeout, /* ticks to wait */
    > int priority /* MSG_PRI_NORMAL or MSG_PRI_URGENT */
    > );
    >
    > And the question is the buffer( char* ) could be a integer variable
    > like - int buf-.
    > that results in problem with little or big endian things.
    >
    > int toBeSent;
    > toBeSent = 0x37;
    > msgQSend( xxx , &toBeSent , sizeof(int) , xxx , xxx );
    >
    > and secondary,
    >
    > int received;
    > msgQReceive( xxx , &received , xxx , xxx , xxx );
    >
    > this received variable could be 0x73 by the CPU??
    >
    > By your concern .
    > Regards ahtz.



  3. Re: Can msgQReceive or msgQSend hold the integer parameter for buffer?


    ahtz wrote:
    > that results in problem with little or big endian things.
    >
    > int toBeSent;
    > toBeSent = 0x37;
    > msgQSend( xxx , &toBeSent , sizeof(int) , xxx , xxx );
    >
    > and secondary,
    >
    > int received;
    > msgQReceive( xxx , &received , xxx , xxx , xxx );
    >
    > this received variable could be 0x73 by the CPU??
    >

    Why would that be? The same CPU is sending and receiving from the
    queue. There is no endian problem. Just cast the integer pointer to a
    char*. As long as the sending and receiving variables are the same
    (i.e., both int), this is portable and defined behavior in the C
    Standard.

    REH


  4. Re: Can msgQReceive or msgQSend hold the integer parameter for buffer?

    Got a little thrown off here too - I think (hope) the "endian" thing is
    a typo...

    REH wrote:
    > ahtz wrote:
    > > that results in problem with little or big endian things.
    > >
    > > int toBeSent;
    > > toBeSent = 0x37;
    > > msgQSend( xxx , &toBeSent , sizeof(int) , xxx , xxx );
    > >
    > > and secondary,
    > >
    > > int received;
    > > msgQReceive( xxx , &received , xxx , xxx , xxx );
    > >
    > > this received variable could be 0x73 by the CPU??
    > >

    > Why would that be? The same CPU is sending and receiving from the
    > queue. There is no endian problem. Just cast the integer pointer to a
    > char*. As long as the sending and receiving variables are the same
    > (i.e., both int), this is portable and defined behavior in the C
    > Standard.
    >
    > REH



  5. Re: Can msgQReceive or msgQSend hold the integer parameter for buffer?


    Troels Jensen wrote:
    > Got a little thrown off here too - I think (hope) the "endian" thing is
    > a typo...
    >

    I don't think so. The OP specifically asked about endian. Unless I am
    misunderstanding your comment....

    REH


  6. Re: Can msgQReceive or msgQSend hold the integer parameter for buffer?

    My goodness.
    Thank you for your deep concern, REH.

    #include


    union{
    int a;
    char ch[4];
    }endian;


    void main()
    {


    int i;

    endian.a = 0x11223344;

    printf("%#x\n", endian.a);

    for(i=0;i<4;i++)
    printf("%#x %#x\n", endian.ch+i, endian.ch[i]);


    }

    in intel
    0x????20 0x44
    0x????21 0x33
    0x????22 0x22
    0x????23 0x11

    but in powerPC
    the reverse will be the answer.

    The matter is how the msgQReceive reads the queue and how the
    msgQSend writes the queue.

    But by REH's thankful answer, I'm gonna beleive him. ^.^;

    Who is Troels Jensen?? I've heard like that for the first time...


    REH 작성:

    > Troels Jensen wrote:
    > > Got a little thrown off here too - I think (hope) the "endian" thing is
    > > a typo...
    > >

    > I don't think so. The OP specifically asked about endian. Unless I am
    > misunderstanding your comment....
    >
    > REH



+ Reply to Thread