Thread: pointer type casting

  1. #1
    char main() RoshanX's Avatar
    Join Date
    Mar 2003
    Posts
    68

    pointer type casting

    hi all,

    Code:
    typedef unsigned int uint32
    typedef unsinged short uint16
    typedef unsinged char uint8
    
    ...
    ...
      uint8* data;
      uint32 source;
      *(uint32*)data=(uint32)source;
    why would this code give the following error
    "invalide operands of type "int" and "uint32*" to binary 'operator*' " ?

    thank you in advance
    First there was God. He was quite lonely, so he created Dennis.
    Dennis was unimpressed with God.
    So, . . . God created Brian..........Khan Klatt
    http://www.clifford.at/fun/GOD

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    1) casting source to uint32 is useless since it's an uint32 already
    2) casting data (uint8*) to uint32* then trying to assign a value will write 3 bytes outside the valid range (DANGER!)
    3) data isn't pointing at anything valid (DANGERx2!)
    4) You should use static_cast and reinterpret_cast instead of the old C-style casts

    What exactly are you trying to do?
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-24-2008, 10:16 AM
  2. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  3. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  4. Erros in Utility Header File
    By silk.odyssey in forum C++ Programming
    Replies: 4
    Last Post: 12-22-2003, 06:17 AM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM