Shouldn't an int pointer in Turbo C be of size 4 bytes?

前端 未结 5 875
长发绾君心
长发绾君心 2020-12-04 03:47

In the Turbo C compiler, the size of an int pointer is shown as 2 bytes when sizeof() operator is used. Now, if I print the address of an int variable, it comes out to be a

5条回答
  •  旧时难觅i
    2020-12-04 04:34

    The true answer of this depends on which setting in Turbo C you are using. Pointers can be 16 or 32-bit, depending on whether they are "near" or "far" pointers. A far pointer can address "all" of the 1MB memory range that a PC from that era (some 20+ years ago) would have, by having a segment portion of 16 bits and a offset portion of 16 bits. These values are combined as (segment << 4) + offset.

    There are "models" of code and data spaces that determine whether you get a near or far pointer for data and/or code.

    This page describes the different models: http://www.tti.unipa.it/~ricrizzo/KS/Data/PBurden/chap6.msdos.memory.html (Although it incorretly states that addresses can reach 256MB - it should be 1MB, and of course since the last 64KB is "BIOS", and memory between A0000-EFFFF is "memory mapped hardware", in practice you can only use up to 64KB [and if you "flip" the A20-gate, you can use 64KB-16 byte above 1MB as RAM, assuming there is RAM above 1MB])

    Of course, like others have said, stop using a compiler that is old enough to get a drivingl license in most countries in the world. There are other products that are much better these days (no matter what your definition of "better" is - unless "comes on floppy disks" is defined as better).

提交回复
热议问题