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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:45:07+00:00 2026-05-26T18:45:07+00:00

first let me say I know the following code will be considered bad practices..

  • 0

first let me say I know the following code will be considered “bad” practices.. But I’m limited by the environment a “little” bit:

In an dynamic library I wish to use “pointers” (to point to classes) – however the program that will use this dll, can only pass & receive doubles. So I need to “fit” the pointer in a double. The following code tries to achieve this, which I hope to work in a 64-bit environment:

EXPORT double InitializeClass() {
    SampleClass* pNewObj = new SampleClass;
    double ret;
    unsigned long long tlong(reinterpret_cast<unsigned long long>(pNewObj));
    memcpy(&ret, &tlong, sizeof(tlong));
    return ret;
}
EXPORT double DeleteClass(double i) {
    unsigned long long tlong;
    memcpy(&tlong, &i, sizeof(i));
    SampleClass* ind = reinterpret_cast<SampleClass* >(tlong);
    delete ind;
    return 0;
}

Now once again I realize I might’ve been better of using vectors & storing the pointers inside the vector. However I really wish to do this using pointers (as alternative). So can anyone tell me possible failures/better versions?

The obvious failure is if double & unsigned long long aren’t the same length in size (or pointers being longer than 64 bits). Is there a method to check this at compile time? – And give a compile error in case the sizes aren’t the same?

  • 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-26T18:45:08+00:00Added an answer on May 26, 2026 at 6:45 pm

    In theory, at least, a 64 bit pointer, type punned to a 64 bit IEEE
    double, could result in a trapping NaN, which would in turn trap. In
    practice, this might not be a problem; my attempts to get trapping NaN
    to actually do something other than be ignored have not been very
    successful.

    Another possible problem is that the values might not be normalized
    (and in fact, probably won’t be). What the hardware does with
    non-normalized values depends: it could either just pass them on
    transparently, silently normalize them (changing the value of the
    “pointer”), or trigger some sort of runtime error.

    There’s also the issue of aliasing. Accessing a pointer through an
    lvalue which has a type of double is undefined behavior, and many
    compilers will take advantage of this when optimizing, assuming that
    changes through a double* or a double& reference cannot affect any
    pointers (and moving the load of the pointer before the write of the
    double, or not reloading the pointer after a modification of the
    double).

    In practice if you’re working in an Intel environment, I think all
    “64-bit” pointers will in fact have the upper 16 bits 0. This is where
    the exponent lives in an IEEE double, and an exponent of 0 is a gradual
    underflow, which won’t trap (at least with the default modes), and won’t
    be changes. So your code might actually seem to work, as long as the
    compiler doesn’t optimize too much.

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

Sidebar

Related Questions

First let me say that I know it's better to use the subprocess module,
Let's say I have the following code: protected void ReservationForm() { double x =
Let's say, that I have the following source output: <p>This is first paragraph</p> <p>This
First let me say that I really feel directionless on this question. I am
First let me say I have read this useful article thoroughly and am using
First let me say that I did see this article: How to remove AspxAutoDetectCookieSupport
First let me explain how I currently handle validation, say, for an IPv4 address:
Let's say the first N integers divisible by 3 starting with 9. I'm sure
Let's say I have a first structure like this: typedef struct { int ivalue;
Let's say I have 3 point clouds: first that has 3 points {x1,y1,z1}, {x2,y2,z2},

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.