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

Ask A Question

Stats

  • Questions 80k
  • Answers 80k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You could show them the results in preview window -… May 11, 2026 at 4:24 pm
  • Editorial Team
    Editorial Team added an answer That code does not call a's constructor. It calls A::operator()(int).… May 11, 2026 at 4:24 pm
  • Editorial Team
    Editorial Team added an answer I recommend you look at my response on your previous… May 11, 2026 at 4:24 pm

Related Questions

I've never been completely happy with the way exception handling works, there's a lot
I'm working on a PHP CMS like project and I'm trying to find out
I've got some Perl code like this: my $match = $matches{$key} ? $matches{$key} was
I was kind of scratching my head at this a week ago, and now

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.