CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: size of pointer

  1. #1
    Join Date
    Sep 2005
    Location
    New Delhi, India
    Posts
    332

    size of pointer

    In turbo C sizeof(pointer)....shows 2 bytes.....whereas in VC6.0 it shows 4 bytes...so does it means it is compiler dependent.......i guess it is......somewhere i read.....i don't remember that...size of pointer is atleast equal to unsigned int or unsigned long int(don't remember which of them)....plz help
    Appreciate others by rating good posts

    "Only buy something that you'd be perfectly happy to hold if the market shut down for 10 years." - Warren Buffett

  2. #2
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470

    Re: size of pointer

    It's architecture dependent. AFAIR, there's nothing in the standard that specifies the size of a pointer with respect to the size of any other type.
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
    --
    Sutter and Alexandrescu, C++ Coding Standards

    Programs must be written for people to read, and only incidentally for machines to execute.

    --
    Harold Abelson and Gerald Jay Sussman

    The cheapest, fastest and most reliable components of a computer system are those that aren't there.
    -- Gordon Bell


  3. #3
    Join Date
    Apr 2005
    Posts
    107

    Re: size of pointer

    Turbo C targets 16 bit enviornments, so uses 16 bit (two byte) pointers (welcome back days of Segmentffset). VC6 targets primarily 32 bit enviornments, and uses 32 bit (four byte) pointers.

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: size of pointer

    A Beginner's Guide to Pointers

    The size of a pointer is 2 bytes on 16 bits platform, and 4 bytes on 32 bit platforms.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  5. #5
    Join Date
    Sep 2005
    Location
    New Delhi, India
    Posts
    332

    Re: size of pointer

    Well i tested on turbo C compiler it showed 2 bytes....in VC 6.0 it showed 4 bytes.....on the same system(32-bit).....is that because in turbo c pointers are by default near pointers....
    Appreciate others by rating good posts

    "Only buy something that you'd be perfectly happy to hold if the market shut down for 10 years." - Warren Buffett

  6. #6
    Join Date
    Apr 1999
    Posts
    27,449

    Re: size of pointer

    Quote Originally Posted by sunnypalsingh
    Well i tested on turbo C compiler it showed 2 bytes....in VC 6.0 it showed 4 bytes.....on the same system(32-bit).....is that because in turbo c pointers are by default near pointers....
    It doesn't matter what system you run Turbo C on -- it won't magically change pointer size because you're running the ancient (more than 15 years old) Turbo C program on a modern 32-bit Windows OS.

    Those "near" and "far" pointers were used in 16-bit MSDOS environments, and the Turbo C compiler is made to compile 16-bit MSDOS programs. If you changed something called the "memory model" when compiling to the "Large Model", you will see by default the pointers contain both segment and offset, making them 32-bits wide. Regardless, the program that is produced will (and always will be) a 16-bit MSDOS program when using Turbo C.

    Regards,

    Paul McKenzie

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