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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:33:12+00:00 2026-06-14T04:33:12+00:00

Verbatim from Linux’ man shmat : RETURN VALUE […] on error (void *) -1

  • 0

Verbatim from Linux’ man shmat:

RETURN VALUE

[…] on error (void *) -1 is returned, and errno is set to indicate the cause of the error.

(POSIX tells the same using a slightly different wording.)

Is there any mandatory rule or definition (standard?) that (void *) -1 may not be a valid address?

  • 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-14T04:33:13+00:00Added an answer on June 14, 2026 at 4:33 am

    To answer the question directly, no, there is no mandatory rule, definition, standard, or specification that says (void *) -1 may not be a valid address.

    (Of course, no rules, definitions, standards, or specifications about memory addresses are mandatory. I see people walking down the street every day without conforming to the C standard, for example, but I have never seen anybody arrested for it. But, even if we omit the mandatory part, using (void *) -1 as an address is generally not prohibited by common specifications.)

    However, it is not necessary for (void *) -1 not to be a valid address in order for shmat to work. It is merely necessary that a successful call to shmat never returns (void *) -1 and that (void *) -1 be supported by the compiler for purposes of testing the return value from shmat. If these two conditions are met, then a program can always distinguish a successful shmat call from an unsuccessful shmat call.

    Regarding the second condition, the C standard does not guarantee that (void *) -1 can be used, so POSIX, in specifying that this is an error return from shmat, implicitly requires the C (or other language) implementation to support it. So this is an extension to the language required by POSIX, and it is generally a simple thing for compilers to support.

    Regarding the first condition, consider when we might want shmat to return (void *) -1 for a successful call. shmat can be called with a user-requested address or without, in which case the implementation chooses an address. In any normal computer architecture, there are multiple reasons to use addresses that are multiples of various values. For shmat, the most obvious is memory mapping. On architectures with virtual memory, memory is mapped in units of pages, and shmat, when it maps memory for the segment, will map to the start of a page. Any even page size has no multiples that are (void *) -1, since the latter is odd, so shmat never chooses to map a segment to (void *) -1. Even if shmat did not use page size, it would typically use some other alignment, such as 4, 8, or 16 bytes, because providing aligned memory means that structures stored at the start of that memory will be aligned, which results in faster memory access on many processors.

    That leaves the case where the user requests (void *) -1 as an address. This would be unusual, and it could work only if the memory segment were a single byte or the memory model allowed wrapping around (or the compiler presented a very strange memory model in which (void *) -1 were not the last byte in the address space). I cannot say for sure whether any POSIX systems support this or not. However, it is clear that this is essentially useless, and nobody has any reason for doing it other than curiosity. Therefore, it is safe and reasonable to rule this case out of shmat, simply saying that is not supported, do not do it.

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

Sidebar

Related Questions

I wrote some html/css/javascript code that was taken verbatim from a javascript textbook. For
As the title suggests, I have copied verbatim the hello.cl and hello.c files from
I'm copying this nearly verbatim from Trent Richardson's impromptu example 10 but I can't
This was taken nearly verbatim from IBM's Mastering Grails series. DateTagLib.groovy: class DateTagLib {
I'm running this php script at my database verbatim from a tutorial, yet I'm
How can I pass a string verbatim from autoconf.ac to automake.am. Example, in autoconf.ac
Background We've been using some code copied verbatim from Joe Duffy's Concurrent Programming on
Consider a verbatim copy of Bloch's Builder pattern (with changes made for C#'s syntax):
This doesn't execute the delimiter (its displayed verbatim in the confirm dialog). Why not?
Does java have an equivalent operator or language construct as the verbatim operator(@) in

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.