Can anyone tell me how to implement sizeof in C language
How to implement sizeof operator in C
Collapse
X
-
Tags: None
-
-
Since you can not write a function that takes a type as an argument you will not be able to do what you wish.
You can get the size of a type programatically but the code would have to be specific to the type.
The sizeof operator exists because there is no real other way to get the functionality it provides and it is something that is useful.Comment
-
Originally posted by ambrnewlearner
necessarily highly platform dependent. That is/was an interesting thread: I
didn't know that some of my compadres had posted in this forum ...
I think it's just a temporary tap from a usenet feed though.
kind regards,
JosComment
-
Originally posted by r035198xA macro that gets the address, adds 1 and subtracts that address would be very close.
1: sizeof ( type-name )
2: sizeof unary-expression
your suggestion only works for the first alternative but what would the size be
of, say '~(a+b++)'? It can't be done without being part of the compiler and knowing
about the platform this darn thing is executed on.
kind regards,
JosComment
-
Originally posted by JosAHOnly partly; there are two forms of the sizeof operator:
1: sizeof ( type-name )
2: sizeof unary-expression
your suggestion only works for the first alternative but what would the size be
of, say '~(a+b++)'? It can't be done without being part of the compiler and knowing
about the platform this darn thing is executed on.
kind regards,
Jos
BTW Have you implemented sizeof in .... <starting to get out of topic here so I'll stop>.Comment
Comment