We know that size of the pointer depends on address bus,so what will be the size of pointer on 8 bit microcontroller like 8051?
-
3It depends on which compiler, which compilation command you use and which OS architecture do you target. Also, size of pointer is either 32-bit or 64-bit depends on stuffs I mentioned and does not depends on stuffs you mentioned. – DMaster Dec 05 '16 at 15:04
-
3The 8051 has a 16-bit address bus, and a 16-bit pointer register called `DPTR`. – Weather Vane Dec 05 '16 at 15:05
-
3@DMaster No, it really doesn't. Pointers will always be 16 bits on any 8051 implementation. Read the question, maybe. – Lundin Dec 05 '16 at 15:20
-
@Lundin Thanks for correct me. I forgot 16-bit arch also exists :) – DMaster Dec 05 '16 at 15:23
-
I once used an 8051 compiler where `char *` was 3 bytes. (17 value bits) – M.M Dec 06 '16 at 00:33
-
@DMaster: 8051 is not a 16 bit arch. I'll leave it as minor task to you finding out which width arch it actually is ... – too honest for this site Dec 06 '16 at 14:26
-
@Olaf Harvard architecture? I have no idea what this is – DMaster Dec 06 '16 at 14:55
-
@DMaster: So why do you comment on something you have no idea about ... – too honest for this site Dec 06 '16 at 15:04
-
@Olaf But I know that it depends on compiler, OS. I just don't know about Harvard architecture – DMaster Dec 06 '16 at 15:09
-
@DMaster: That has nothing to do with Harvard vs. Von-Neumann. And 8051 typically has no OS. Normally the OS is the least a factor for choosing pointer size anyway. – too honest for this site Dec 06 '16 at 15:13
-
@Olaf You can not force a 32-bit OS to use 64-bit pointers, that for sure. For "8051 typically has no OS", in fact no circuit (or device) has OS by default – DMaster Dec 06 '16 at 15:18
3 Answers
The 8051 is not a C friendly processor.
It has several address spaces. I used the Keil 8051 compiler extensively and it had several pointer types.
- An 8 bit pointer to point at the internal memory space or internal indirect space.
- A 16 bit pointer to point to either external ram or code space.
- A "smart" 24 bit pointer that could point anywhere. Basically a tag followed by 16 bits.
All of this is without the added complexity of bank switching schemes that make things even more "interesting".
The smart pointers where to be avoided because they were big and slow.

- 1,882
- 15
- 17
-
hello, have you ever seen a processor with a bus on N wires where the C compiler does not implement the C abstract machine using all the N physical wired, and some of the N wires of the bus are dummy during execution of a C program ? – alinsoar Dec 06 '16 at 01:20
-
1Actually yes, the 8051. This is not a "C" issue. This is an 8051 issue. Given a nice 16 bit pointer to XDATA, there are no values for that pointer that will access DATA or IDATA or CODE space. You need different types of pointers for that or the so called slow, large, smart pointer. To understand this, you need a deep dive into the 8051. This is left as an exercise for the reader ;-) – Peter Camilleri Dec 06 '16 at 02:01
-
DIfferent pointer sizes to the same object types in against the standard. Thus basically the "smart pointer" would be the only compliant pointer type (with all implied obstacles). But I agree this is one of the worst architectures when it comes to High-Level Languages and without the non-standard extensions one should consider either a different architecture or using a good Assembly-language. I prefere the first option; 8051 is outdated since >20 years (the architecture has been from the day of its presentation, only justified by compactness and price and was never meant for HLL). – too honest for this site Dec 06 '16 at 15:23
-
There are a number of C compilers available for the 8051, and C is often used on them. First thing to do is realize you probably don't want to write ANSI or ISO standard C on one. For one thing, the type promotion rules are performance killers on 8-bit. – Randy Howard Feb 07 '18 at 20:20
A compliant C compiler requires SIZE_MAX
to be at least 65535 (0xFFFF). This implies an object pointer must be at least 16 bits.
Given the 8051 architecture, it is not likely to have a wider pointer, but could. It depends on the compiler and more than just the processor, but the target platform with its memory. The extended 8051 family does include 32-bit machines.
Note that an object pointer and function pointer may have different widths.

- 143,097
- 13
- 135
- 256
-
1A pointer need not have the same size as `size_t`. In fact, that's the reason `(u)intptr_t` exist. There is no relation between pointer width and any integer width apart that `(u)intptr_t` are large **enough**. – too honest for this site Dec 06 '16 at 12:30
-
"A pointer need not have the same size as size_t" is true but is irrelevant here as this answer asserts an object pointer needs at _least_ the size as `size_t`. – chux - Reinstate Monica Dec 06 '16 at 17:22
-
It was exactly my point this assertion is false. A pointer very well can be smaller than `size_t`. – too honest for this site Dec 06 '16 at 17:24
-
@Olaf It would have been better is the 1st comment used the "smaller" claim as it better details your point. If you have a complaint C example that exhibits your claim of object pointer smaller than `size_t`, I'll gladly remove this answer. Our varied experiences are certainly extensive, yet not having come across such a platform, even though theoretically possible, leads to that consideration is not of practical concern. – chux - Reinstate Monica Dec 06 '16 at 17:38
The limits imposed by stdint.h contain the constants INTPTR_MIN/INTPTR_MAX
in both freestanding and hosted implementations (4. Conformance, ISO/IEC 9899:
).
From 7.18 Integer types <stdint.h>
7.18.2.4 Limits of integer types capable of holding object pointers
— minimum value of pointer-holding signed integer type
INTPTR_MIN −(2^15 − 1)
— maximum value of pointer-holding signed integer type
INTPTR_MAX 2^15 − 1
— maximum value of pointer-holding unsigned integer type
UINTPTR_MAX 2^16 − 1
If you have an exotic processor that has an address bus of 8 you cannot implement C on it, but surely such a processor does not exist.
If you have a processor that has a bus width of 16 and a data bus of 3 bits, you can implement the data types imposed by the C abstract machine, but using many fetches for each operation.
Also, on exotic architectures, it is not a direct correspondence (isomorphism) between the bits from the abstract C machine and the physical wires. Some wires may not be used, other wires could keep correction codes, other wires may generate trap representation. On such architectures it is more difficult to make implementations of C.

- 15,386
- 4
- 57
- 74
-
3But C compilers for 8051 are seldom compliant - to be so would be to fail to take advantage of its architecture, or be sympathetic to its severe constraints. 8051 uses a Harvard architecture with separate code, external-data, internal-data and a bit addressable overlay region. The IDATA space is 256 bytes, (and the bit region 256 bits); a compiler will indeed generate 8 bit pointers for those spaces - it is possible to use more "redundant" bits to be compliant, but given the disadvantages of such an approach it would be an unlikely solution. – Clifford Dec 06 '16 at 03:29