C Board  

Go Back   C Board > General Programming Boards > C Programming

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 10-25-2006, 12:01 AM   #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"
enggabhinandan is offline  
Old 10-25-2006, 12:05 AM   #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.
__________________
Enlighten Yourself

I'm back!
Wraithan is offline  
Old 10-25-2006, 12:07 AM   #3
Registered User
 
Join Date: Oct 2006
Location: Canada
Posts: 1,219
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
nadroj is offline  
Old 10-25-2006, 12:11 AM   #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.....
enggabhinandan is offline  
Old 10-25-2006, 12:25 AM   #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.
__________________
Enlighten Yourself

I'm back!
Wraithan is offline  
Old 10-25-2006, 12:33 AM   #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....
enggabhinandan is offline  
Old 10-25-2006, 12:44 AM   #7
Registered User
 
MacNilly's Avatar
 
Join Date: Oct 2005
Posts: 217
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.
MacNilly is offline  
Old 10-25-2006, 02:46 AM   #8
Its hard... But im here
 
swgh's Avatar
 
Join Date: Apr 2005
Location: England
Posts: 1,467
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
swgh is offline  
Old 10-25-2006, 02:50 AM   #9
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,492
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
CornedBee is offline  
Old 10-25-2006, 03:34 AM   #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.
kevin_cat is offline  
Old 10-25-2006, 05:30 AM   #11
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,630
Need to find the solution for the Macro
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.

Salem is offline  
Closed Thread

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
WS_POPUP, continuation of old problem blurrymadness Windows Programming 1 04-20-2007 06:54 PM
facing problem with Buffer enggabhinandan C Programming 5 11-22-2006 06:26 AM
Problem related to string class & lpthread on HP-UX 11iV2 molus C++ Programming 2 06-21-2006 04:23 AM
Laptop Problem Boomba Tech Board 1 03-07-2006 06:24 PM
Sorting problem.. well actually more of a string problem fatdunky C Programming 5 11-07-2005 11:34 PM


All times are GMT -6. The time now is 01:47 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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