actually, I was thinking arbitrary that i should make my own sizeof function. till date, i have made many many my own C functions which are also defined in C libraries. but i got strucked in sizeof operator desiging. can anyone give me hint how to start with this ? i am not aksing code as per rules of daniweb.
nitin1
15
Master Poster
Recommended Answers
Jump to PostKeep in mind that you won't be able to perfectly simulate sizeof because it's a compile time operator. But you can get somewhat close for the type syntax with pointer arithmetic:
#define SIZEOF(type) (int)((char*)((type*)0) - (char*)((type*)0 + 1))
It's not strictly portable, but I've yet to …
Jump to Postcompile type operator ?
Compile time operator. It means that the compiler already has all of the information it needs while compiling the code. The vast majority of this information is discarded by the time the code actually runs, which puts you at a significant disadvantage when trying …
Jump to PostI've been taught in my freshman class that
sizeof
was a function, or at least it was persistently addressed as such, and I didn't really know any better at the time. I think he is under the same boat.
sizeof
is not a function, but is more of an operator. …
All 11 Replies
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
nitin1
15
Master Poster
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
asrockw7
18
Junior Poster in Training
nitin1
15
Master Poster
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
nitin1
15
Master Poster
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
nitin1
15
Master Poster
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.