CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2005
    Posts
    7

    Red face Our Own code for Sizeof() operator

    Hi all,

    I tried for this and I am unable to get an idea, how to write my own code for sizeof.
    My english is poor. pls understand.For to understand i am writing an example below:

    main()
    {
    int i;
    printf("size of integer is = %d",sizeof(i));
    }

    output:
    size of integer is = 2

    Now, here i want write my own function for to calute size of integer.

    Thank u..

  2. #2
    Join Date
    Sep 2008
    Posts
    5

    Re: Our Own code for Sizeof() operator

    how about this macro from another forum
    i havent tried this out yet

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

    e.g
    mySizeof(int)
    int a;
    mySizeof(a);

  3. #3
    Join Date
    May 2002
    Posts
    10,943

    Re: Our Own code for Sizeof() operator

    Welcome to the forums, swtsvn.

    Please remember to keep your posts relevant. This thread is over 4 years old!
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured