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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:50:05+00:00 2026-05-11T12:50:05+00:00

There was some code like this: // Convenience to make things more legible in

  • 0

There was some code like this:

// Convenience to make things more legible in the following code const float & x = some.buried.variable.elsewhere;  // Go on to use x in calculations... 

I have been told that the ‘const float &’ is ‘bad’ and should just be a plain float or const float.

I, however, could not think of a compelling reason other than ‘you don’t have to type ‘&”.

In fact, it seems to me that in some cases the original could be better, since compiler might not allocate extra stack space to the variable.

In other words, originally I could validly say:

assert(&x == &some.buried.variable.elsewhere) 

Whereas in the second case I cannot.

Also, the original seems to communicate intent better, in my view, since the whole point of a reference is to make an alias to another value.

Can anyone give me examples of where the ‘const float &’ version is worse than a plain ‘float’ or ‘const float’ in some tangible way?

  • 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. 2026-05-11T12:50:06+00:00Added an answer on May 11, 2026 at 12:50 pm

    I can’t think of a reason why const float & would be better than const float.

    References make sense if you’re either worried about copies being made (which is irrelevant with a primitive type like float) or you want to be able to update a value across all instances that share the reference (which is irrelevant with const members).

    On top of that, references in members are a huge pain in the neck* when it comes to initialization, and so they’d have to offer a significant advantage of the alternatives in order to be useful, and it’s clearly not the case with const float.


    * The FQA on references is always amusing and thought provoking

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

Sidebar

Related Questions

There's some code in our project that looks a bit like this: Private Sub
There are some fairly powerful tools like SIMBL or Airfoil/Instant Hijack which use code
I am reading WIX script written by others. There are some code really confuses
We're storing some Guid's in a MS SQL database. There's some legacy code that
In some existing code there is a test to see if the user is
Today, I have seen some legacy code. In the destructor there is a statement
I'm refactoring some old JavaScript code and there's a lot of DOM manipulation going
I have some jQuery/JavaScript code that I want to run only when there is
We have some old C code here that's built with nmake. Is there an
Is there any way to improve code completion in notepad++? Currently it supports some

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.