public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Philip <snzzbk@gmail.com>
To: gcc-help@gcc.gnu.org
Subject: reinterpret_casting a non-POD
Date: Sat, 16 Aug 2008 12:31:00 -0000	[thread overview]
Message-ID: <25c035550808160442n695bb421m79e58ede2d203e0@mail.gmail.com> (raw)

Given a simple but currently non-POD class such as:

struct Point
{
  float x, y, z;

  Point () {}
  Point (float x_, float y_, float z_): x (x_), y (y_), z (z_) {}
};

Is there any risk involved in the following operations?:

Point p;
float* pp = reinterpret_cast<float*> (&p);

void* buffer = // acquire memory
Point* points = reinterpret_cast<Point*> (buffer);
// do stuff that treats buffer as array of Points
float* floats = reinterpret_cast<float*> (points);

Thanks.

             reply	other threads:[~2008-08-16 11:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-16 12:31 Philip [this message]
2008-08-17  4:08 ` Eljay Love-Jensen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=25c035550808160442n695bb421m79e58ede2d203e0@mail.gmail.com \
    --to=snzzbk@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).