Thread: Typecast Array to Uload

  1. #1
    Unregistered
    Guest

    Question Typecast Array to Uload

    I am having problems trying to typecast a array with four elements into a ulong. I figure it must look like something like

    Ulong longthing = (ULong) Array[]

    But if the array has four elements then how are they ordered in the ULong?

    I have been looking around online and have not found and Array to float type casts. Can I even do this?

    Clueless

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    You can't cast it, you have to do this

    memcpy( &longthing, Array, sizeof(longthing) );

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Actually, you can do this....
    Code:
    unsigned long container = * ((unsigned long *) array)
    No promises about what the result will be.
    Callou collei we'll code the way
    Of prime numbers and pings!

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    I know that you can map a bit-string onto structures. But I've never tried the other way or with arrays. After some experimenting I got the following result with GCC.

    unsigned char array [4] = {0x01, 0x01, 0x03, 0x04};
    unsigned long *container;

    container = (unsigned long *) array;

    printf ("%X\n", *container);

    Output: 4030101

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10:33 AM
  3. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM