int pointers in structs

This is a discussion on int pointers in structs within the C Programming forums, part of the General Programming Boards category; hi, this code doesn't work, (the record_de_list assignment) and I would just like to know why. Code: u8_t record_de_list = ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    61

    int pointers in structs

    hi,

    this code doesn't work, (the record_de_list assignment) and I would just like to know why.

    Code:
        u8_t record_de_list = 0x19;
        
        record->hdl = sdp_next_rhdl();
        record->record_de_list = &record_de_list;  // <-- this line
        record->len = 3;
    here is the definition

    Code:
    struct sdp_record {
      struct sdp_record *next; /* For the linked list */
      
      u32_t hdl; /* Service Record Handle */
      u8_t *record_de_list;
      u8_t len;
    };

    thanks for your help

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    What do you mean by "doesn't work".

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    61
    well, it generates a "makes pointer to integer without a cast" and when i print it its a memory address...

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by davo666 View Post
    well, it generates a "makes pointer to integer without a cast" and when i print it its a memory address...
    Then you need to show us the code you're using. The code you posted does no such thing.

  5. #5
    Registered User
    Join Date
    Jan 2009
    Posts
    61
    Sorry:

    (the problem is spread over three files...)

    header file:

    Code:
    struct sdp_record {
      struct sdp_record *next; /* For the linked list */
      
      u32_t hdl; /* Service Record Handle */
      u8_t *record_de_list;
      u8_t len;
    };
    function2:

    Code:
       printf("record de: %d",record->record_de_list);
    function1:

    Code:
      record = lwbt_memp_malloc(MEMP_SDP_RECORD);
        
        u8_t record_de_list = 0x19;
        
        record->hdl = sdp_next_rhdl();
        record->record_de_list = &record_de_list;
        record->len = 3;
    
    function2(record);
    functions 1 and two are in the same file, function1 calls function2 and passes the struct.

    (also should the struct be extern?)

    thanks for your help

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You've got a problem in the print statement; record->record_de_list is a pointer but you're trying to print it as a number. But not on the line with the & on it.

  7. #7
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    pointers should be printed with %p format (anc casted to (void*) for it)
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  8. #8
    Registered User
    Join Date
    Jan 2009
    Posts
    61
    yeah,

    I meant to print what record_de_list pointed to.

    thanks for helping me

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  2. Replies: 3
    Last Post: 05-13-2007, 08:55 AM
  3. Converted from Dev-C++ 4 to Dev-C++ 5
    By Wraithan in forum C++ Programming
    Replies: 8
    Last Post: 12-03-2005, 06:45 AM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  5. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 05:05 PM

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