Binary Copy

This is a discussion on Binary Copy within the C++ Programming forums, part of the General Programming Boards category; If I had this... Code: struct PointType { int x; int y; }; struct RectangleType { PointType topLeft; PointType extent; ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    73

    Binary Copy

    If I had this...
    Code:
    struct PointType
    {
       int x;
       int y;
    };
    
    struct RectangleType
    {
       PointType topLeft;
       PointType extent;
    };
    ...and this...
    Code:
    struct RCType
    {
       int Col;
       int Row;
       int Cols;
       int Rows;
    };
    ...could I safely binary copy one over to the other?...
    Code:
    RectangleType Rect = { { 4, 2 }, { 40, 24 } };
    RCType RC = *( (RCType*)&Rect );
    It seems like it should work, but I don't know how the compiler organizes structures.

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Its actually quite simple:

    You don't. Reason being is that the compiler is allowed to make some adjustments that would screw up any bitwise (not binary) operations.

    Best method would be to write a constructor that took in two points and made a rectangle out of them.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. denary to binary problems
    By redruby147 in forum C Programming
    Replies: 6
    Last Post: 02-09-2009, 05:21 PM
  2. how to copy binary files using Unix API's
    By rohan_ak1 in forum C Programming
    Replies: 25
    Last Post: 05-07-2008, 10:12 AM
  3. I need help with decimal to binary Algorithm
    By webznz in forum C Programming
    Replies: 4
    Last Post: 03-13-2008, 04:52 AM
  4. arrays vs lists? And containers in general!
    By clegs in forum C++ Programming
    Replies: 22
    Last Post: 12-03-2007, 02:02 PM
  5. binary
    By webturtle0 in forum A Brief History of Cprogramming.com
    Replies: 52
    Last Post: 12-05-2002, 02:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21