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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:53:28+00:00 2026-06-01T09:53:28+00:00

So i’ve been writing some applications in C and using OpenMP for parallelization. I

  • 0

So i’ve been writing some applications in C and using OpenMP for parallelization. I implemented a Monte-Carlo Pi estimate and found that the normal rand() function is not reentrent and thread-safe. The recommendation is to use the drand48_r option.

Now here is the problem, my application compiles fine on Linux eg. Ubuntu, Fedora and CentOS but does not compile on Mac OS X. The compile error on OS X is.

simple.c:7: error: storage size of ‘randBuffer’ isn’t known

The code used as the simple example is:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[]) {

  double x;
  struct drand48_data randBuffer;

  srand48_r(time(NULL), &randBuffer);

  drand48_r(&randBuffer, &x);

  printf("Random number: %f\n", x);

  return EXIT_SUCCESS;
}

I read up about it and I found a note in the man pages that,

These functions are GNU extensions and are not portable.

Here is a link to it: http://www.kernel.org/doc/man-pages/online/pages/man3/drand48_r.3.html

So I have a number of questions;

  1. What are GNU extensions and what makes it non portable?
  2. What alternatives do I have for random number generation on OS X that is also thread-safe?

Well that is about it.

The example is compiled with gcc as,

gcc simple.c -o simple

  • 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-01T09:53:29+00:00Added an answer on June 1, 2026 at 9:53 am

    I don’t really see the gain of using drand48_r over erand48. erand48 has the same type of random generator as drand48 but compared to that receives the state of the random generator as a function parameter, so it perfectly does the job.

    The _r extensions store the result in place (the second parameter) and return an error code that is always guaranteed to be 0. I don’t see much use in all of this. I’d stick to the POSIX interfaces (in particular erand48).

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I am doing a simple coin flipping experiment for class that involves flipping a

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.