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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:55:59+00:00 2026-05-20T00:55:59+00:00

I use the Airplay SDK which is a platform for building C++ apps for

  • 0

I use the Airplay SDK which is a platform for building C++ apps for smartphones. It also has a x86 simulator which uses MS Visual C++ IDE + compiler.

Now, I have this class :

namespace Fair {

    class Bitmap : public Sprite {

    public:

        const CIw2DImage* const& getBitmapData() { return bitmapData; }; // warning: returning reference to temporary

    private:

        CIw2DImage* bitmapData;
    };

}

I get the above warning if I build with GCC (ARM) Debug. I don’t get a warning with (x86) Debug.

I asked elsewhere and I got this reply :

Because `const CIw2DImage* const’ is a
const pointer to const CIw2DImage, and
Bitmap::bitmapData is a pointer to
non-const CIw2DImage compiler
automatically casts pointer to
non-const to const, so here’s a
temporary. The following code might be
generated by a “typical” compiler:

const CIw2DImage* const& getBitmapData() {
    const CIw2DImage* const tmp = bitmapData;
    return tmp;
}

Probably (x86) compiler doesn’t detect
this problem.

You might want to remove reference
symbol (&) from the prototype (why do
you want use a reference in this
case?)

If a compiler does that, then it’s totally wrong practice..? Making the value returned more “strict” is simply at compiler-level, to prevent “abuse”. (x86) doesn’t detect because it doesn’t “cause” the problem in the 1st case..?

I return a reference to a pointer for the sole reason to “save” 32 bits of memory, i.e. use the same block of memory as the bitmapData pointer but within a different context.

Any comments please?

  • 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-20T00:56:00+00:00Added an answer on May 20, 2026 at 12:56 am

    You won’t save any memory at all returning a reference, it’s just a pointer internally. In addition, const occurs completely at compile-time, there’s no reason for any temporary to be produced- and even if it was, a const reference to it would be valid.

    That code looks terrible to me personally but it’s not undefined in any way.

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

Sidebar

Related Questions

I want to use Airplay to send images in high definition to a Apple
use this code, in the Preferences activity, to know when the reset preference has
I'm newbie in developing apps for smartphones, but have lots of experience writing desktop
Use: The user searches for a partial postcode such as 'RG20' which should then
Use case: we have some project meta-data files which we want tracked, but are
Use case: -Visual Studio is open -Master branch is clean (confirmed with git status)
Use Case Show a photo uploaded by the user in a square box with
use C#,want to upload excel file on google doc. bellow syntax use to upload
use Text::Table; my $tb = Text::Table->new(Planet,Radius\nkm,Density\ng/cm^3); $tb->load( [ Mercury,2360,3.7], [ Mercury,2360,3.7], [ Mercury,2360,3.7], );
use strict; use warnings; use Time::HiRes qw(sleep); use Test::WWW::Selenium; use Test::More no_plan; use Test::Exception;

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.