Raw assignment doesn't work!

This is a discussion on Raw assignment doesn't work! within the C++ Programming forums, part of the General Programming Boards category; Code: PIXELFORMATDESCRIPTOR pfd = 0x28000100250000000020000000000000000000000000001000000000000000000000000000000000; I'm sure you see what I'm trying to do. Anyway, the error is conversion from ...

  1. #1
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,620

    Raw assignment doesn't work!

    Code:
    PIXELFORMATDESCRIPTOR pfd = 0x28000100250000000020000000000000000000000000001000000000000000000000000000000000;
    I'm sure you see what I'm trying to do. Anyway, the error is
    conversion from `int' to non-scalar type `tagPIXELFORMATDESCRIPTOR' requested
    Why won't it let me do a raw assignment? And how do I get around that?
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  2. #2
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,620
    Also,
    Code:
       PIXELFORMATDESCRIPTOR pfd;
       memset(&pfd, 0x28000100250000000020000000000000000000000000001000000000000000000000000000000000, sizeof(PIXELFORMATDESCRIPTOR));
    Doesn't work.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  3. #3
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630
    What are you trying to do?

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    My first choice would be struct initialization the normal way.

    But if you want to copy a byte array, it is done something like this.
    Code:
       const unsigned char init[] =
       {
          0x28,0x00,0x01,0x00,0x25,0x00,0x00,0x00,
          0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
       };
       PIXELFORMATDESCRIPTOR pfd;
       memcpy(&pfd, init, sizeof pfd);
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    You cannot have integer literals larger than the largest type. Also, it wouldn't help you because memset's parameter only takes an int.

    What's wrong with just initializing the PIXELFORMATDESCRIPTOR's fields?
    Code:
    PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1,
      PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL,
      PFD_TYPE_RGBA, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0 };
    It's a bit more readable than the "raw assignment" (there's no such thing).
    Even more readable would be to assign the fields by name.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,620
    Yeah, I'm just doing that...

    How did you know those where my member contents?
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Yarin View Post
    Yeah, I'm just doing that...

    How did you know those where my member contents?
    Because that's the order your data is in, perhaps?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Nah, can't be anything that obvious. It must be because I'm psychic
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu
    By Krush in forum C Programming
    Replies: 17
    Last Post: 09-01-2009, 02:34 AM
  2. Help with a pretty big C++ assignment
    By wakestudent988 in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2006, 08:46 PM
  3. Help required! Bowling Assignment.
    By Pacino in forum C Programming
    Replies: 22
    Last Post: 12-08-2005, 11:55 AM
  4. Raw Sockets and SP2...
    By Devil Panther in forum Networking/Device Communication
    Replies: 11
    Last Post: 08-12-2005, 04:52 AM
  5. How does this work?...assignment using vectors...
    By Gamma in forum C++ Programming
    Replies: 1
    Last Post: 04-22-2002, 03:58 PM

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