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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:55:33+00:00 2026-05-16T07:55:33+00:00

Possible Duplicate: Why is my return type meaningless? Hi, I’m confused about a particular

  • 0

Possible Duplicate:
Why is my return type meaningless?

Hi, I’m confused about a particular const conversion. I have something like

// Returns a pointer that cannot be modified,   
// although the value it points to can be modified.  
double* const foo()  
{  
    static double bar = 3.14;  
    return &bar;  
}

int main()  
{  
    double* const x = foo(); // fine  
    const double* y = foo(); // eh?!  
    return 0;  
}

When I compile this on MSVS 2008 (Express) there is no error, but it seems to me like there should be. The meaning behind x and y are quite different, so it does not seem like there should be this implicit conversion. So is this an issue with the compiler (unlikely), or my understanding of the const-ness involved here (quite likely).

  • 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-16T07:55:34+00:00Added an answer on May 16, 2026 at 7:55 am

    The return value cannot be modified. That is, the pointer cannot be modified. However, because at the call site, the return value is an rvalue (without a defined = operator), it cannot be modified anyway.

    If the return value was an lvalue (e.g. a reference), this would be possible:

    double* &foo()
    {
        static double bar = 3.14;
        double *barP = &bar;
        return barP;
    }
    
    double myDouble;
    foo() = &myDouble;
    

    But this would not be possible:

    double* const &foo()
    {
        static double bar = 3.14;
        double *barP = &bar;
        return barP;
    }
    
    double myDouble;
    foo() = &myDouble; // error!
    

    Adding const to the return value (as to quality the pointer as const, not the pointed to data as const) in your case does nothing. If anything, your compiler should warn you about this, because really there’s no different if you just remove the const qualifier (barring possible ABI changes, though I’m not sure if the standard allows for ABI changes in this case).

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

Sidebar

Related Questions

Possible Duplicate: LINQ to SQL: Return anonymous type? I have a standard LINQ to
Possible Duplicate: Java - why no return type based method overloading? The compiler does
Possible Duplicate: How can I use a carriage return in a HTML tooltip? I'd
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
Possible Duplicate: Default value of a type In C#, to get the default value
Possible Duplicate: How do I calculate someone's age based on a DateTime type birthday?
Possible Duplicate: Why do I get error: … must be a reference type in
Possible Duplicate: Method overloading in Objective-C? Is method overloading not possible. I have two
Possible Duplicate: How do you return 'not uint' in C#? Hi Everyone, I'm trying
Possible Duplicate: PHP EOF shows only one result from loop Hello Seems like I

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.