GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 385 of 453    Print  
How to write a sizeof function using a macro function?

  
Total Answers and Comments: 4 Last Update: October 19, 2007     Asked by: mani2881 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
October 17, 2007 00:55:48   #1  
gsivaprakashreddy Member Since: September 2007   Contribution: 2    

RE: How to write a sizeof function using a macro funct...



#define size_of(data) ( (char *)(&data +1) - (char *)(&data))



with regards.
G. Siva Prakash Reddy.


 
Is this answer useful? Yes | No
October 17, 2007 01:23:00   #2  
G. Siva Prakash Reddy        

RE: How to write a sizeof function using a macro funct...

Hi!

#define size_of(data) ( (char *)(&data +1) - (char *)(&data))

with Regards

G. Siva Prakash Reddy.


 
Is this answer useful? Yes | No
October 18, 2007 05:43:17   #3  
mani2881 Member Since: July 2007   Contribution: 5    

RE: How to write a sizeof function using a macro funct...

Hi Siva

I guess i will have to elaborate my question. Will this work when i give

sizeof(int) ?


 
Is this answer useful? Yes | No
October 19, 2007 11:06:48   #4  
mani2881 Member Since: July 2007   Contribution: 5    

RE: How to write a sizeof function using a macro funct...
Hi Siva

This would be the correct

#include<stdio.h>

#define mySizeof(x)(mySizeof1(x))

#define mySizeof1(x){__typeof__(x) tmp ;(char*)(&tmp + 1) - (char*)(&tmp);}

main()

{

int a;

printf("size of int dn" mySizeof(int));

printf("size of a dn" mySizeof(a));

}

Thanks for post
Mani


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape