Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8245801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:18:10+00:00 2026-06-07T22:18:10+00:00

I am making a message queue API in C, but I am having a

  • 0

I am making a message queue API in C, but I am having a problem with the receive method. I send a char* message (“BOB”) to the message queue and it is successfully stored. I then try to receive the message but that fails.

Inside mq_receive() the correct message is dequeued and ret_val->buf points to 0x012f5754 (“BOB”). Next, msg_ptr (which is originally 0x00000000) is assigned 0x012f5754. Everything works as expected until the program returns to main(). In main(), receive_message is still NULL. I was expecting it to point to the first character of BOB which is 0x012f5754. What am I doing wrong? Thanks.

//main.c
main(){
    char* receive_message = NULL;
    //message queue init ...
    mq_send(msq_id, "BOB"); //this works correctly
    mq_receive(msq_id, receive_message);      
    printf("return value: %p\n", receive_message); 
}

//message_queue.c
mqd_t mq_receive(mqd_t mqdes, char *msg_ptr)
{
    queue_t* ret_val;
    q_attr* attr_ptr = (q_attr*)mqdes;
    ret_val = dequeue(attr_ptr);
    //all this works ret_val->buf points to BOB
    msg_ptr = ret_val->buf;
    return mqdes;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T22:18:12+00:00Added an answer on June 7, 2026 at 10:18 pm

    Arguments are passed by value in C, you need to pass the address of receive_message to mq_receive():

    mqd_t mq_receive(mqd_t mqdes, char **msg_ptr)
    {
        queue_t* ret_val;
        q_attr* attr_ptr = (q_attr*)mqdes;
        ret_val = dequeue(attr_ptr);
        //all this works ret_val->buf points to BOB
        *msg_ptr = ret_val->buf;
        return mqdes;
    }
    

    and invoke it:

    mq_receive(msq_id, &receive_message);  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a problem querying the message count from the remote msmq queue. This
I'm making simple XMPP client using Jabber-Net. To send simple message i'm using a
I'm making a little message sending module. It'll handle queuing messages from a request
After making cabal install of the darcsden code I get this message: cabal: The
I am making an android game that should display a message that you have
Making a new site but something is happening to it in IE8. The social
Making a new site but something is happening to it in IE. I've purchased
Having set up a ReferenceDataRequest I send it along to an EventQueue Service refdata
I've been making a Window class for a game, and I'm having trouble with
I'm making an app that starts a Service that sends SMS message periodically under

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.