Thread: facing problem in understanding this....

  1. #1
    Registered User
    Join Date
    Mar 2006
    Location
    Bangalore, INDIA
    Posts
    43

    facing problem in understanding this....

    Hi,
    I'm facing one more problem, i'm not able to understand the below way of casting, whats actually happening here....
    Code:
    #define X(t,m) (size_t) ( (char *) &((t*)0)->m - (char *)(t*)0)
    whats the meaning of " &((t*)0)" .....is it something like "address of zero cast to pointer of t"

  2. #2
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Go to your teacher and request either some tutoring or to be removed from the class.

    Or really just read your book or pay attention in class.

    In anycase stop posting every little question you get.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    it looks like: the address of member 'm', from (t) pointer 0.. heh, its really confusing.

    break it up into parts to visualize what it is:

    Code:
    &(          )->m           <---- 'address of' member variable 'm', from this object:
        (t*) 0                  <---- zero casted to a 't' pointer.. which is NULL
    or thats how i see it

  4. #4
    Registered User
    Join Date
    Mar 2006
    Location
    Bangalore, INDIA
    Posts
    43
    Thanks Nadroj....thank u very much
    and Wraithan if u dont want to suggest then please keep quiet, the forums are present to help the people who are studying on there own. i'm studying on my own and if i find any problem in understanding then ofcourse i will seek the help in this forum, if u r not interested in answering then why cant u be quiet.....

  5. #5
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Most of your questions so far have either been homework/exam questions. And the others with a little googling you would have found the answers.

    Refer to the link in my sig for a more indepth reasoning.

  6. #6
    Registered User
    Join Date
    Mar 2006
    Location
    Bangalore, INDIA
    Posts
    43
    i had taken few tests online to check my level of understanding and those question were the one which i never went through and could not understand at all.....for u it may look like very silly but for me a small thing information makes lot of difference....

  7. #7
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    Quote Originally Posted by enggabhinandan
    Hi,
    I'm facing one more problem, i'm not able to understand the below way of casting, whats actually happening here....
    Code:
    #define X(t,m) (size_t) ( (char *) &((t*)0)->m - (char *)(t*)0)
    whats the meaning of " &((t*)0)" .....is it something like "address of zero cast to pointer of t"
    That code is god awful. There is a struct or class involved because of the -> operator. the (char *) are casts to bytes and well X is just really really vague name for a macro.

  8. #8
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    On a side note I hate using #define. I only use it when using header gaurds in header files

    But #define is used much more in C than C++. I usually use a constant variable instead

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Looks like an implementation of the offsetof macro to me. These things are not to be looked at, IMO.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  10. #10
    Registered User
    Join Date
    Jun 2005
    Posts
    10
    Quote Originally Posted by CornedBee
    Looks like an implementation of the offsetof macro to me. These things are not to be looked at, IMO.
    I think so, too!

    Code:
    &((t*)0)->m
    is the address of member m. And
    Code:
     (t*)0
    is the address of struct t.

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    http://cboard.cprogramming.com/showthread.php?t=84470
    Not showing effort gets you black marks
    Repeatedly asking the same question isn't good either.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  2. facing problem with Buffer
    By enggabhinandan in forum C Programming
    Replies: 5
    Last Post: 11-22-2006, 06:26 AM
  3. Replies: 2
    Last Post: 06-21-2006, 04:23 AM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  5. Replies: 5
    Last Post: 11-07-2005, 11:34 PM