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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:34:39+00:00 2026-06-12T16:34:39+00:00

Modern compilers can optimize code when they see a const . However, I’ve never

  • 0

Modern compilers can optimize code when they see a const. However, I’ve never seen the C standard library use const for its non-pointer arguments. For example memcmp() is an example of this. It has 2 const void * arguments, but its third argument is size_t.

Why is the standard library (and other libraries) designed this way? Why don’t I see const size_t or const int in modern code?

  • 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-12T16:34:40+00:00Added an answer on June 12, 2026 at 4:34 pm

    Those consts mean different things. In

    int memcmp ( const void * ptr1, const void * ptr2, size_t num );
    

    const void * ptr1 means that memcmp will treat ptr1 as pointing to constant data and won’t modify it; similarly for const void * ptr2. Thus, the caller knows that the stored values won’t be changed and can optimize accordingly. In a function call like

    int result = memcmp(ptr1, ptr2, num);
    

    the variables ptr1, ptr2, and num are copied into the function. memcmp makes no promises not to adjust them; it only promises not to adjust what the pointers point to. Indeed, it might increment/decrement any of the copied variables in order to step through the arrays if that proves efficient. If it wanted to promise not to change any of them, the declaration would be:

    int memcmp ( const void *const ptr1, const void *const ptr2, const size_t num );
    

    For simple data types (like pointers and integers), little (if any) optimization can be gained in this way, and the original specifiers of this function (and others) apparently saw no reason to prevent implementations from modifying the variables in fortuitous circumstances.

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

Sidebar

Related Questions

For desktop browser all modern browser uses Zoom functionality so we can use PX
I know, that modern compilers can do procedural integration not only with functions defined
While using modern C++ compilers (including MSVC, GCC, ICC), how can I say if
Are there any general rules I can use for evaluating whether a modern compiler
Modern browsers are supposed to support the CSS page-break properties to some degree. However
use Modern::Perl; use Algorithm::Permute; use List::AllUtils qw/uniq/; find_perms(1151); sub find_perms { my ($value) =
use Modern::Perl; use DateTime; use autodie; my $dt; open my $fh, '<', 'data.txt'; #
In most modern IDEs there is a parameter that you can set to ensure
For each of the modern browsers are there well known hooks I can tie
The book 'Modern Compiler Design' is the nice book about compilers. In its source

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.