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 186715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:41:44+00:00 2026-05-11T15:41:44+00:00

Due to my feeble understanding of allocating type memory to pointers, the following causes

  • 0

Due to my feeble understanding of allocating type memory to pointers, the following causes a bus error on the call to barrier_create (‘hi’ is never printed).

typedef struct barrier barrier_t; typedef struct barrier *barrier_p;  barrier_p test_barrier_p;  int main(int argc, char *argv[]) {     barrier_create(*test_barrier_p); }  int barrier_create(barrier_p *barrier_pointer) { printf('hi\n');     barrier_p old_barrier, new_barrier;     int count;     old_barrier = (barrier_p) *barrier_pointer;     new_barrier = (barrier_p) malloc(sizeof(*new_barrier));     count = pthread_mutex_init(&new_barrier->lock, NULL);     new_barrier->is_valid = VALID_BARRIER;     new_barrier->counter = 0;     new_barrier->release_flag = 0;     *barrier_pointer = new_barrier;     return HAPPY_HAPPY_JOY_JOY; } 

What am I missing or mis-typing?

  • 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. 2026-05-11T15:41:45+00:00Added an answer on May 11, 2026 at 3:41 pm
    barrier_create(*test_barrier_p); 

    Since barrier_create takes address of a barrier_p, this should be &test_barrier_p, not *test_barrier_p.

    printf('hi\n'); 

    Inaccurate test of code reachability because stdout is likely buffered; I’d recommend fprintf(stderr, 'hi\n'); instead.

    new_barrier = (barrier_p) malloc(sizeof(*new_barrier)); 

    I’d say sizeof(barrier_t). Again a * in an odd place, the _p notation may not be helping your type manipulation clarity.

    For pedanticism, I would check the return value of malloc. I see little point in keeping the old value unless to recover in some way from a malloc error.

    What is the purpose of count?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Due to repetitive errors with one of our Java applications: Engine engine_0: Error in
Due to company constraints out of my control, I have the following scenario: A
Due to comments I added the following code (in BasicPanel) Connect(CTRL_ONE, wxEVT_KILL_FOCUS, (wxObjectEventFunction)&BasicPanel::OnKillFocus); Connect(CTRL_TWO,wxEVT_KILL_FOCUS,
Due to a bug that was fixed in C# 4, the following program prints
Due to user error, a situation has arisen in which my database holds an
Due to validation markup and some other reasons I disable the list-style-type css property
Due to some memory problems I had to textureBitmap.recycle() all texture bitmaps after I
Due to an error in the system a tracking log was firing repeatedly causing
Due to continuing crash problems, I'm about to uninstall and reinstall my copy of
Due to the lack of clientaccesspolicy.xml, there appears to be problems with using Amazon

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.