0

Is there any link or someone has maintained a single matrix of C C/C++ Pointer(s) sizes on different platform (linux, windows 32, windows 64 etc.).

I am looking for a matrix where i could find max information related to pointer sizes.

I tried and tried but miserably failed to search something useful.

Edit 1: No i didn't find a Matrix on the above duplicate link.

Edit 2:

Standard data types on UNIX, Linux, and Windows

+————————————-+—————————————+—————————————————+—————————————————+—————————————————+—————————————————+—————————————————+
| Name        | WIn32       | Win64           | Unix32          | Unix64          | Linux32         | Linux64         |
+————————————-+—————————————+—————————————————+—————————————————+—————————————————+—————————————————+—————————————————+
| char        |             | 1 byte          | 1 byte          | 1 byte          | 1 byte          | 1 byte          |
+-------------+-------------+-----------------+-----------------+-----------------+-----------------+-----------------+
| short       |             | 2 bytes         | 2 bytes         | 2 bytes         | 2 bytes         | 2 bytes         |
+-------------+-------------+-----------------+-----------------+-----------------+-----------------+-----------------+
| int         |             | 4 bytes         | 4 bytes         | 4 bytes         | 4 bytes         | 4 bytes         |
+-------------+-------------+-----------------+-----------------+-----------------+-----------------+-----------------+
| long        |             | 4 bytes         | 4 bytes         | 8 bytes         | 4 bytes         | 8 bytes         |
+-------------+-------------+-----------------+-----------------+-----------------+-----------------+-----------------+
| float       |             | 4 bytes         | 4 bytes         | 4 bytes         | 4 bytes         | 4 bytes         |
+-------------+-------------+-----------------+-----------------+-----------------+-----------------+-----------------+
| double      |             | 8 bytes         | 8 bytes         | 8 bytes         | 8 bytes         | 8 bytes         |
+-------------+-------------+-----------------+-----------------+-----------------+-----------------+-----------------+
| long double |             | 8 bytes         | 16 bytes *02    | 16 bytes *04    | 16 bytes *02    | 16 bytes *04    |
+-------------+-------------+-----------------+-----------------+-----------------+-----------------+-----------------+
| pointer     |             | 8 bytes *01     | 4 bytes         | 8 bytes         | 4 bytes         | 8 bytes         |
+-------------+-------------+-----------------+-----------------+-----------------+-----------------+-----------------+
| ptrdiff_t   |             | 8 bytes         | 4 bytes         | 8 bytes         | 4 bytes         | 8 bytes         |
+-------------+-------------+-----------------+-----------------+-----------------+-----------------+-----------------+
| size_t      |             | 8 bytes         | 4 bytes         | 8 bytes         | 4 bytes         | 8 bytes         |
+-------------+-------------+-----------------+-----------------+-----------------+-----------------+-----------------+
| time_t      |             | 8 bytes         | 4 bytes         | 8 bytes         | 4 bytes         | 8 bytes         |
+-------------+-------------+-----------------+-----------------+-----------------+-----------------+-----------------+
| clock_t     |             | 4 bytes         | 4 bytes         | 8 bytes *05     | 4 bytes         | 8 bytes *05     |
+-------------+-------------+-----------------+-----------------+-----------------+-----------------+-----------------+
| wchar_t     |             | 2 bytes         | 4 bytes *03     | 4 bytes *03     | 4 bytes *03     | 4 bytes *03     |
+-------------+-------------+-----------------+-----------------+-----------------+-----------------+-----------------+
| Word        |             | 2 bytes         |                 |                 |                 |                 |
+-------------+-------------+-----------------+-----------------+-----------------+-----------------+-----------------+
| Dword       |             | 4 bytes         |                 |                 |                 |                 |
+-------------+-------------+-----------------+-----------------+-----------------+-----------------+-----------------+
| Handle      |             | 8 bytes         |                 |                 |                 |                 |
+-------------+-------------+-----------------+-----------------+-----------------+-----------------+-----------------+
| Hfile       |             | 4 bytes         |                 |                 |                 |                 |
+-------------+-------------+-----------------+-----------------+-----------------+-----------------+-----------------+

*01 - Note that all pointers are 8 bytes
*02 - Note that on AIX and Linux PPC a long double is 8 bytes
*03 - Note that on AIX a wchar_t is 2 bytes
*04 - Note that on AIX and Linux PPC a long double is 8 bytes.
*05 - Note that on the other UNIX platform a clock_t is 4 bytes.

ACom
  • 13
  • 3
  • 3
    32 bit program -> 32 bit pointers. 64 bit program -> 64 bit pointers. Really. It's that simple. – user253751 Sep 10 '20 at 10:43
  • 7
    Please note that there's no such language as "C/C++" and that many of us old-timers dislike that term. There are the two *very* different languages C and C++, and you need to keep them separate. – Some programmer dude Sep 10 '20 at 10:43
  • 1
    @Someprogrammerdude do they differ in how long the pointers are? – Tommylee2k Sep 10 '20 at 10:46
  • 3
    C++ supports certain kinds of pointers that C does not, and those can be different sizes (I'm thinking specifically of member function pointers). Many of the other rules around pointers are different too. – BoBTFish Sep 10 '20 at 11:01
  • Just run printf("%d\n", sizeof(void *)); on each platform – Maximilian Voss Sep 10 '20 at 11:09
  • 2
    This question is not a duplicate of the linked one. The linked one is about C++, this question is about C (According to the title). However, he added also C++ in the description and tag. which is a bit confusing. – 12431234123412341234123 Sep 10 '20 at 11:09
  • 4
    @MaximilianVoss This causes UB, use the format specifier `%zu` for size_t, which comes from `sizeof` – 12431234123412341234123 Sep 10 '20 at 11:12
  • 1
    @user253751 that isn't completely true. For example x32abi on Linux runs in 64-bit mode but the pointer is 32-bit long. You can achieve the same thing [in Windows](https://stackoverflow.com/a/55460361/995714). In fact for 64-bit MIPS, Sparc or PowerPC it's very common for programs to still use 32-bit pointers because those architectures don't have a bigger number of registers to compensate for the increase in pointer size like in x86 and ARM64 – phuclv Sep 10 '20 at 15:08
  • @ACom: While "duplicate" could be not the best close reason for your question, you question is badly fitted for the Stack Overflow. With your specification of different platforms as "linux, windows 32, windows 64 etc." the formulae from the [first comment](https://stackoverflow.com/questions/63827970/c-pointer-sizes#comment112868353_63827970) is quite precise. You could get more specific answers with more specific platform descriptions. And note, that a request for off-site resources is off-topic on Stack Overflow, see [help/on-topic]. – Tsyvarev Sep 10 '20 at 22:39
  • example of Matrix https://docs.oracle.com/cd/E19253-01/817-6223/chp-typeopexpr-2/index.html – ACom Sep 11 '20 at 05:23
  • So, the generic fundamental dimensions that i can guess could be 4: ( (C or C++) (16 or 32 or 64) (OS e.g. Windows, Linux) (Data Types) ) – ACom Sep 11 '20 at 05:28

0 Answers0