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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:40:43+00:00 2026-06-10T06:40:43+00:00

Taking this struct: struct Foo { float m_foo; // no other member }; //

  • 0

Taking this struct:

struct Foo
{
    float m_foo;
    // no other member
};

// A Foo object.
Foo f;

Which is more costly?

float result = std::sin(f.m_foo);

or

float result = std::sin(*(reinterpret_cast<float*>(&f)));
// f can be interpreted like float in this case

I think the second case is faster, but i don’t have sure because i don’t know how the compiler will handle it. What you can tell me about it?

  • 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-10T06:40:44+00:00Added an answer on June 10, 2026 at 6:40 am

    Which is more costly?

    IME, the one invoking Undefined Behavior is always more costly in the end.

    If you want to port this to some new platform, or another compiler, or a new version of your compiler, such code might blow up. Or it might make some other, innocent looking code blow up. Or it might do so only on Sundays, when your customers cannot call support. (They will call on Monday then, so you should take off on Monday as often as possible if you write such code.) Or it might only do so when your boss is around, or at full moon, or at compiler versions built at the first of the month.

    If you have some concrete case where you need to speed up some code, and you found, through profiling, that this piece of code is a bottleneck, then measure whether this brings any relevant performance advantages, using your real application and real data. If it does, then in God’s name use it in this one place, but put some very visible comment there, explaining what you do and why.

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

Sidebar

Related Questions

Taking a JavaScript object with 4 properties: function Object() { this.prop1; this.prop2; this.prop3; this.prop4;
I have this query which is a dependant query and taking much execution time
Taking the following snippet as an example: struct Foo { typedef int type; };
Taking this file as an example, I'm trying to read the data in a
I want to process every element of a for-loop. Taking this code, why is
Is it possible to somehow do this without taking out the @? It does
How to implement a gmail-like this is taking too long warning message using jQuery
Refreshing on floating points (also PDF ), IEEE-754 and taking part in this discussion
After taking a look at this SO question and doing my own research, it
This problem is taking me too long to fix I could use some guidance

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.