Thread: Subtracting a macro from a pointer

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    26

    Subtracting a macro from a pointer

    Hi all,

    I am trying to subtract the value of a macro from a pointer but after this operation, I still get the same pointer address.

    In particular, why the following code

    Code:
    	struct list_head *init_tasks = tasks;
    	printk("init_task next task is: 0x%X\n", init_tasks->next);
    gives the same result with this?:

    Code:
    	init_tasks = (uint8_t*)(init_tasks->next - (uint32_t)SEGMENT_OFFSET);
    	printk("init_task next task (phys) is: 0x%X\n", init_tasks);
    Could anyone let me know what I am doing wrong?

    Thanks in advance.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    What is the definition of SEGMENT_OFFSET ?

    Also which compiler and OS is this for?

  3. #3
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    What is tasks??
    Basically tasks->next = (uint8_t*)(init_tasks->next - (uint32_t)SEGMENT_OFFSET)
    Are you implying this?
    Not enough code. WTF is value of init_tasks for 2nd code segment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Subtracting Strings
    By rondel in forum C Programming
    Replies: 4
    Last Post: 03-16-2010, 08:17 PM
  2. Subtracting from strings?
    By Xfacter in forum C++ Programming
    Replies: 7
    Last Post: 08-25-2006, 12:01 AM
  3. Subtracting Two Pointers
    By z0diac in forum C Programming
    Replies: 28
    Last Post: 02-26-2004, 10:55 PM
  4. Adding and subtracting.
    By erikcn in forum C++ Programming
    Replies: 2
    Last Post: 06-01-2002, 05:01 AM

Tags for this Thread