Thread: Raw assignment doesn't work!

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

    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?

  2. #2
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Also,
    Code:
       PIXELFORMATDESCRIPTOR pfd;
       memset(&pfd, 0x28000100250000000020000000000000000000000000001000000000000000000000000000000000, sizeof(PIXELFORMATDESCRIPTOR));
    Doesn't work.

  3. #3
    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,005
    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,895
    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
    2,158
    Yeah, I'm just doing that...

    How did you know those where my member contents?

  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,895
    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, 09:46 PM
  3. Help required! Bowling Assignment.
    By Pacino in forum C Programming
    Replies: 22
    Last Post: 12-08-2005, 12:55 PM
  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