As you already mentioned sizeof is an operator and not a lib fn. Which means it will be evaluated/code for it will be replaced at compile time rather than during execution.
It will follow the following grammar, unary_operator: sizeof , and others sizeof: ( unary expression | type_name) and so on for unary expression and type_name which would eventually result in built-in or user-defined data-types whose 'size' can be inferred from symbol table. If some one needs to code a size of operator, it won;t be possible since you can not actually pass type in c, there can be ways to do this using macros like using stringization of macro. On Mon, May 31, 2010 at 1:14 PM, debajyotisarma <sarma.debajy...@gmail.com>wrote: > This is not about algorithms,but related to C programming. > > How to implement sizeof operator? > > macro for this > #define my_sizeof(a) (char*)(&a+1)-(char*)&a > > this works fine of variables > int a; > printf("%d",my_sizeof(a)); //or even for user defined > structures > > but it will not work for data types > > like > > printf("%d",my_sizeof(int)); > > so please get another solution. > function will be preferable.not macro > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.