Problems with arrays

This is a discussion on Problems with arrays within the C Programming forums, part of the General Programming Boards category; Hello I am trying to declare this an array like this Code: unsigned long *data[] = {0x61626364, 0x65800000, 0x00000000 } ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    15

    Unhappy Problems with arrays

    Hello

    I am trying to declare this an array like this

    Code:
    unsigned long *data[] = {0x61626364, 0x65800000, 0x00000000 }
    because I need to pass this array to a function
    but i get warnings that says "initialization makes pointer from integer without a cast " and "assigments makes integer from pointer without a cast"

    If I declare the array like this
    Code:
    unsigned long data[3] = {0x61626364, 0x65800000, 0x00000000 }
    I then I pass tu my function like this
    Code:
    func(&data[0])
    I get an error that says that memory 0x... couldnot be written

    I need some help, anybody?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by steffi View Post
    Hello

    I am trying to declare this an array like this

    Code:
    unsigned long *data[] = {0x61626364, 0x65800000, 0x00000000 }
    because I need to pass this array to a function
    but i get warnings that says "initialization makes pointer from integer without a cast " and "assigments makes integer from pointer without a cast"
    Yes, that is an array if pointers, that you initialize with the integer value 0x61626364, etc - and the compiler thinks "well, that's an integer, assigned to a pointer - I wonder if that's what the author wanted? I'd better issue a warning.".

    If I declare the array like this
    Code:
    unsigned long data[3] = {0x61626364, 0x65800000, 0x00000000 }
    I then I pass tu my function like this
    Code:
    func(&data[0])
    I get an error that says that memory 0x... couldnot be written

    I need some help, anybody?
    What does "func" do?
    &data[0] should give you the address of data. But func(data) should work just fine too.

    --
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problems with arrays
    By vikingcarioca in forum C Programming
    Replies: 4
    Last Post: 03-31-2009, 07:21 AM
  2. Replies: 16
    Last Post: 01-01-2008, 03:07 PM
  3. My Arrays!!!, My Arrays!!! Help!?
    By llcool_d2006 in forum C++ Programming
    Replies: 1
    Last Post: 12-10-2006, 11:07 AM
  4. Problems with Strings and Arrays.
    By SlyMaelstrom in forum C++ Programming
    Replies: 13
    Last Post: 04-15-2005, 02:13 PM
  5. Help!!! Problems with arrays.
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-08-2002, 08:21 PM

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