great size pointer in gcc

size of float pointer in c
size of char pointer in c
size of double pointer in c
size of char pointer in c
sizeof(ptr)
size of void pointer in c
size of char pointer in 32 bit compiler

I want to define a great size pointer(64 bit or 128 bit) in gcc which is not depend on platform. I think there is something like __ptr128 or __ptr64 in MSDN.

sizeof(__ptr128) is 16 bytes.
sizeof(__ptr64 ) is 8  bytes.

is it possible?

it can be useful when you use kernel functions in 64 bit OS which requires 8 bytes pointer argument and you have a 32 bit application which uses 32 bits address and you want to use this kernel function.

Your question makes no sense. Pointers, by definition, are a memory address to something - the size must depend upon the platform. How would you dereference a 128-bit pointer on a hardware platform supporting 64-bit addressing?!

You can create 64 or 128-bit values, but a pointer is directly related to the memory addressing scheme of the underlying hardware.

EDIT

With your additional statement, I think I see what you're trying to do. Unfortunately, I doubt it's possible. If the kernel function you want to use takes a 64-bit pointer argument, it's highly likely to be a 64-bit function (unless you're developing for some unusual hardware).

Even though it's technically possible to mix 64-bit instructions into a 32-bit executable, no compiler will actually let you do this. A 64-bit API call will use 64-bit code, 64-bit registers and a 64-bit stack - it would be extremely awkward for the compiler and operating system to manage arbitrary switching from a 32-bit environment to a 64-bit environment.

You should look at finding the equivalent API for a 32-bit environment. Perhaps you could post the kernel function prototype (name+parameters) you want to use and someone could help you find a better solution.

Just so there's no confusion, __ptr64 in MSDN is not platform independent:

On a 32-bit system, a pointer declared with __ptr64 is truncated to a 32-bit pointer.

What is the size of a pointer variable?, I want to define a great size pointer(64 bit or 128 bit) in gcc which is not depend on platform. I think there is something like __ptr128 or __ptr64 in MSDN. On most general-purpose platforms in use today, the size of any pointer type will be either four chars (for 32-bit systems) or eight chars (for 64-bit systems). Depending on the array’s element size, the result of the integer division will be either 8, 4, 2, 1 or 0, regardless of the number of elements.

Can't comment, but the statement that you can't use 64 bit instructions in a "32 bit executable" is misleading since the definition of "32 bit executable" is subject to interpretation. If you mean an executable that uses 32 bit pointers, then there is nothing at all that says you can't use instructions that manipulate 64 bit values while using 32 bit pointers. The processor doesn't know the difference.

Linux even supports a mode where you can have a 32 bit userspace and a 64 bit kernel space. Thus, each app has access to 4GB of RAM, but the system can access much more. This keeps the size of your pointers down to 4 bytes but does not restrict the use of 64 bit data manipulations.

Coding resources, cat main.c #include <stdio.h> int main(void) { printf("The size of an int pointer is %​ld bytes!\n", size of a void pointer is %ld bytes!\n", sizeof(void *)); return (0); } $ gcc main.c -o size $ . Allow me to re-introduce your new best friend, pointers. 6.24 Arithmetic on void- and Function-Pointers. In GNU C, addition and subtraction operations are supported on pointers to void and on pointers to functions. This is done by treating the size of a void or of a function as 1. A consequence of this is that sizeof is also allowed on void and on function types, and returns 1.

I'm late to the party but the question makes quite a lot of sense in embedded platforms.

If you combine a CPU with some additional accelerators in the same SOC, they don't necessarily need to have the same address space or address space size.

For the firmware in the accelerator you would want pointers that cover its address space from the CPU and the accelerator's perspective. They are not necessarily the same size.

For example, with a 64 bit CPU and a 32 bit accelerator, the pointer for the firmware can cover 32 bit long address space and the pointer for CPU covers 64 bit address space. C does not have two or more void * types depending on the address spaces you want to talk to.

People generally solve this by casting void * to uintN_t with N as large as needed and passing this around between different parts of the system.

Is the sizeof(some pointer) always equal to four?, Pointer in C hold the address of the variable and points to the value stored at that address. On 32-bit machine sizeof pointer is 32 bits ( 4 bytes), while on 64 bit machine it's 8 byte. Regardless of what data type they are pointing to, they have fixed size. great size pointer in gcc. I want to define a great size pointer(64 bit or 128 bit) in gcc which is not depend on platform. I think there is something like __ptr128 or __ptr64 in MSDN.

There is none, because gcc was not designed for embedded architectures. There are architectures where multiple sized pointers exist like for example m16c: ram has 16 bit addresses and rom(flash) has 20 bit addresses in the same address space. The performance and size usage is better for smaller pointers.

How many bytes do pointers take up?, The built-in functions described below yield the best results when used For example, to detect object sizes across function boundaries or to follow pointer  You can choose a size from 1 to 15 (which is very large). Choose a new color in the “Change Pointer Color” section. There are four options here: white with a black border (the default), black with a white border, inverted (for example, black on a white background or white on a black background), or your selected color with a black border.

great size pointer in gcc - linux - jQuery, The size of void pointer varies system to system. If the system is 16-bit, size of void pointer is 2 bytes. If the system is 32-bit, size of void pointer  7.2 Restricting Pointer Aliasing As with the C front end, G++ understands the C99 feature of restricted pointers, specified with the __restrict__ , or __restrict type qualifier. Because you cannot compile C++ by specifying the -std=c99 language flag, restrict is not a keyword in C++.

What is the size of a pointer in C?, It is also not that hard to verify this by simply printing sizes of pointers of greater than one passed to A's method by 32 bytes – an exact size of  3.10 Options That Control Optimization. These options control various sorts of optimizations. Without any optimization option, the compiler's goal is to reduce the cost of compilation and to make debugging produce the expected results. Statements are independent: if you stop the program with a breakpoint between statements, you can then assign a new value to any variable or change the program

Object Size Checking (Using the GNU Compiler Collection (GCC)), Size and alignment of basic data types gives the size and natural alignment of the basic data types. Size and alignment of data types Type Size in bits Natural alignment in bytes char 8. All pointers, 32, 4 (word-aligned) of a long long is at the low address in little-endian mode, and at the high address in big-endian mode. 3.7.2 Common Predefined Macros. The common predefined macros are GNU C extensions. They are available with the same meanings regardless of the machine or operating system on which you are using GNU C or GNU Fortran. Their names all start with double underscores. __COUNTER__. This macro expands to sequential integral values starting from 0.

Comments
  • How exactly are you going to make use of a pointer that is larger than your address space?
  • As @adelphus says in his answer below, platform -independent pointer size definition does not make sense. That being said, there is a __int128 type for 128 bit integers in GCC 4.6 (but not older)
  • it can be useful when you use kernel functions in 64 bit OS which requires 8 bytes pointer argument and you have a 32 bit application which uses 32 bits address and you want to use this kernel function.
  • So what you really want is a 32/64 bit pointer, not a 128 bit pointer. Which is really just a 64 bit pointer, anyway (with the upper half zero for 32 bits...). Or, just a pointer, because on a 32 bit system you can't have a 64 bit pointer that isn't totally bogus, and on a 64 bit system, a pointer is already 64 bits in any case. Which makes the entire endeavour a bit absurd to begin with. Or, if you are paranoid about struct padding/alignment, you might want to wrap a void* and a uint64_t into an union with appropriate conversion operators.
  • Yep! i think so. but I like to have more details and an example if there is!
  • PowerPC has an ABI for 64-bit instructions with 32-bit executables, as does MIPS (n32).
  • A complete AVR toolchain (an 8-bit processor) would suggest it handles embedded arch just fine, not to mention the many ARM ISAs and platforms that gcc has been ported to.
  • Still it is a hack and architecture specific. Different pointer sized are not handled in a generic way. Each architecture has its own named address spaces, where smaller pointer sizes could be used on any architecture to save space. I still stand by my assertion that gcc was not designed for embedded hardware, that it is used for that, that is another thing. I still can not specify my own pointer size in a type.
  • See gcc-renesas.com/migration-guides/iar-m16cm32c/index.html for example: __far or __data is not supported by gcc, and you cannot make a pointer 20 bit and use another that is 16 bit, because gcc cannot differentiate them, or better to say, there is no simple user interface to specify this in a generic way.
  • Also if gcc would be designed for embedded, it would have C extensions that would make it aware of Hardware architectures by making pointers include memory region property. For example gcc on AVR will gladly accept data pointer as format in printf_P without warning or anything.