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

  • SEARCH
  • Home
  • 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 8259703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:55:33+00:00 2026-06-08T02:55:33+00:00

Okay, first I will begin with some background. I’m working on a project for

  • 0

Okay, first I will begin with some background.
I’m working on a project for a class that involves a client and a server. They are two separate processes that communicate with each other through what we are calling request channels.

The client collects command line arguments for the number of requests, the size of the buffer for the request channels, and the number of worker threads that send the requests (-n, -b, and -w respectively).

How ever many worker threads the user wants is how many request channels I must create between the client and server.

RequestChannel *channel;

int main(int argc, char * argv[])
{
    char *n=NULL, *b=NULL, *w=NULL;
    int num, buf, workers;
    char optchar=0;

    while((optchar=getopt(argc,argv,"n:b:w:"))!=-1)
    switch(optchar)
    {
        case 'n':
            n=optarg;
            break;
        case 'b':
            b=optarg;
            break;
        case 'w':
            w=optarg;
            break;
        case '?':
            break;
        default:
            abort();
    }
    num=atoi(n);
    buf=atoi(b);
    workers=atoi(w);

    channel=malloc(workers*sizeof(RequestChannel));

    cout << "CLIENT STARTED:" << endl;

    pid_t child_pid;
    child_pid = fork();

    if(child_pid==0)
    {
       execv("dataserver", argv);
    }
    else
    {
        cout << "Establishing control channel... " << flush;
        RequestChannel chan("control", RequestChannel::CLIENT_SIDE);
        cout << "done." << endl;

        for(int i=0;i<workers;i++)
            RequestChannel channel[i](chan.send_request("newthread"), RequestChannel::CLIENT_SIDE);
    }
}

I’m getting compile errors with the malloc line and I don’t know what the issue is. I just want to be able to access each RequestChannel like channel[i].

The way it is now, I receive an error saying

invalid conversion from void* to RequestChannel*

When I replace the sizeof(RequestChannel) with sizeof(*RequestChannel), I receive an error saying

expected primary-expression before ‘)’ token.

  • 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-08T02:55:35+00:00Added an answer on June 8, 2026 at 2:55 am

    The malloc line is correct (but please check if it returns NULL). A C++ compiler (not C) complains since in C++ you need a cast:

    channel = static_cast<RequestChannel *>malloc(...);
    

    or, with C syntax:

    channel = (RequestChannel*) malloc(...);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, some Guys will know what i mean and edit my Question but they
first, I can't stand Crystal! Okay, that's off my chest... Now, we have an
Okay, so I'm using perl to read in a file that contains some general
Okay, first off I will attempt to explain what I'm trying to do. I
Okay, sample code first; this is my attempt at communicating what it is that
Okay I will first admit I don't know the proper terminology for all this
Okay, I know that I've not been the best at accept rate...and I will
Okay, I'm trying to create a simple app that will draw a shape (I'm
For the first time, I am writing a web service that will call upon
Okay, I am trying to integrate some C code into a C++ project, and

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.