简体   繁体   English

64位Solaris编译中的32位指针

[英]32 bit pointer in a 64 bit Solaris compile

I know this is a strange questions but I was wondering if it was possible to make a 32 bit pointer in 64 bit compile on Solaris using g++. 我知道这是一个奇怪的问题,但是我想知道是否有可能在使用g ++的Solaris上以64位编译方式生成32位指针。 The final object would need to be 64 bit however one of my pointers offsets is becomming larger on Solaris then it is in windows if I do use 64 bit to compile. 最终对象将需要为64位,但是如果我确实使用64位进行编译,那么我的指针偏移量之一在Solaris上将变得更大,然后在Windows中变为。 This is causing a big problem. 这引起了很大的问题。 I was wondering if it was possible to make a 32bit pointer within my 64 bit compiled object. 我想知道是否有可能在64位编译对象中创建32位指针。

Pointer size is a property of your target architecture, so you cannot mix and match 32- and 64-bit pointers. 指针大小是目标体系结构的属性,因此您不能混合和匹配32位和64位指针。 I would strongly suggest re-thinking your design (which smells like usual mistake of casting pointers to integers and back.) You can theoretically work with "limited-reach" offsets, but again please ask yourself why, and what would be a better way of doing it. 我强烈建议重新考虑您的设计(闻起来像是将指针转换为整数然后返回的常见错误。)从理论上讲,您可以使用“有限范围”偏移量,但是请再次问自己为什么,什么是更好的方法做到这一点。

You can't change regular pointers, the size of a pointer is sizeof(void *) . 您不能更改常规指针,指针的大小为sizeof(void *) And if you could, what would you do with an 32bit pointer on an 64bit system? 如果可以的话,在64位系统上使用32位指针该怎么办?

Do you mean pointers in C or do you maybe mean pointers to a file offset? 您是指C语言中的指针,还是指文件偏移量的指针?

If you have pointer type there, then you shouldn't make it 32-bit in 64-bit program. 如果在那里有指针类型,则不应在64位程序中将其设置为32位。 If it is just some offset that not related to memory model, then you could use different type with stable size across platforms, something like uint32_t . 如果仅仅是与内存模型无关的偏移量,则可以在平台上使用大小稳定的其他类型,例如uint32_t

It does not make sense to "need" a 32 bit pointer on a 64 bit machine. “需要” 64位计算机上的32位指针没有任何意义。 I also dont understand this line: 我也不明白这一行:

The final object would need to be 64 bit however 最终对象将需要为64位

I would take a closer look and try to fix the bug on your end. 我会仔细研究一下,然后尝试修复该错误。 If you post some example code we may be able to help more. 如果您发布一些示例代码,我们可能会提供更多帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM