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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:41:10+00:00 2026-05-20T13:41:10+00:00

I am not so well-versed in the C standard, so please bear with me.

  • 0

I am not so well-versed in the C standard, so please bear with me.

I would like to know if it is guaranteed, by the standard, that memcpy(0,0,0) is safe.

The only restriction I could find is that if the memory regions overlap, then the behavior is undefined…

But can we consider that the memory regions overlap here ?

  • 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-20T13:41:11+00:00Added an answer on May 20, 2026 at 1:41 pm

    I have a draft version of the C standard (ISO/IEC 9899:1999), and it has some fun things to say about that call. For starters, it mentions (§7.21.1/2) in regards to memcpy that

    Where an argument declared as size_t n specifies the length of the array for a
    function, n can have the value zero on a call to that function. Unless explicitly stated
    otherwise in the description of a particular function in this subclause, pointer arguments
    on such a call shall still have valid values, as described in 7.1.4
    . On such a call, a
    function that locates a character finds no occurrence, a function that compares two
    character sequences returns zero, and a function that copies characters copies zero
    characters.

    The reference indicated here points to this:

    If an argument to a function has an invalid value (such as a value
    outside the domain of the function, or a pointer outside the address space of the program,
    or a null pointer, or a pointer to non-modifiable storage when the corresponding
    parameter is not const-qualified) or a type (after promotion) not expected by a function
    with variable number of arguments, the behavior is undefined.

    So it looks like according to the C spec, calling

    memcpy(0, 0, 0)
    

    results in undefined behavior, because null pointers are considered “invalid values.”

    That said, I would be utterly astonished if any actual implementation of memcpy broke if you did this, since most of the intuitive implementations I can think of would do nothing at all if you said to copy zero bytes.

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

Sidebar

Related Questions

I should say first, that I'm not very well-versed in testing my code, and
I need to use basic javascript here and I'm not well versed with it.
Hey guys, im not well versed in dealing with asynchronous design patterns, and im
I'm not well versed in domain driven design and I've recently started created a
I would like to find out if my database is running or not from
I'm not very well versed with regular expressions. I've had to use them, maybe
I'm really not well versed in these things, I just want to setup an
I am not a well-versed programmer so i don't want to use a complicated
I am writing an extension (my first want, also I am not well versed
I'm not very well versed with regular expressions so i need some help. I'm

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.