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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:05:04+00:00 2026-05-27T07:05:04+00:00

Is the defacto method for comparing arrays (in C) to use memcmp from string.h

  • 0

Is the defacto method for comparing arrays (in C) to use memcmp from string.h?

I want to compare arrays of ints and doubles in my unit tests

I am unsure whether to use something like:

double a[] = {1.0, 2.0, 3.0};
double b[] = {1.0, 2.0, 3.0};
size_t n = 3;
if (! memcmp(a, b, n * sizeof(double)))
    /* arrays equal */

or to write a bespoke is_array_equal(a, b, n) type function?

  • 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-05-27T07:05:04+00:00Added an answer on May 27, 2026 at 7:05 am

    memcmp would do an exact comparison, which is seldom a good idea for floats, and would not follow the rule that NaN != NaN. For sorting, that’s fine, but for other purposes, you might to do an approximate comparison such as:

    bool dbl_array_eq(double const *x, double const *y, size_t n, double eps)
    {
        for (size_t i=0; i<n; i++)
            if (fabs(x[i] - y[i]) > eps)
                return false;
        return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a built in method or defacto default plugin that will let you
Possible Duplicate: “Web interface” to PHPUnit tests? Are there any PHP unit testing systems
I don't see this answered any where on the web, amazingly. Unit tests in
Lastly I've been feeling like jQuery is slowly becoming the defacto standard in JS
License keys are the defacto-standard as an anti-piracy measure. To be honest, this strikes
I wonder if I should use the CAS protocol or OAuth + some authentication
What's the current defacto standard for ASP.NET mobile development across a wide variety of
Is there a best practice or defacto standard with how much of the GORM
I'm learning Python and decided to start familiarizing myself with the (defacto?) Python web
Is it possible for a developer to use Scala without knowing Java? Is it

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.