简体   繁体   English

GCC Quad大小32和64位

[英]GCC quad size 32 and 64 bit

I'm using GCC compiler on Linux. 我在Linux上使用GCC编译器。
I want to use 64 bit compiler and build some of my files with -m32 option (32 bit compatibility). 我想使用64位编译器,并使用-m32选项(32位兼容性)构建某些文件。 I found strange (for me) behavior of compiler. 我发现了奇怪的编译器行为。
My code is simple: 我的代码很简单:

int main () {
   int test =(((0) & 0x00000000) << (32));
   return 0;
}

And for this code I received warning for 32 , 64 and 64 with -m32 compilers: 和用于这个代码我接收的警告为326464-m32编译器:

warning: left shift count >= width of type [enabled by default]

But when I'm trying to compile it from assebmly code : 但是,当我尝试从assebmly code进行编译时:

.quad (((0) & (0x00000000)) << (32))

I received warning only for 32 bit compiler: 我只收到32 bit编译器的警告:

Warning: shift count out of range (32 is not between 0 and 31)

Why warnings are differ for same code compiled from c and asm file for different compilers (32 and 64 bit)? 为什么对于从casm文件编译的相同代码,对于不同的编译器(32和64位),警告会有所不同?

EDIT: 编辑:

Where can I find .quad definition, i mean in code? 我在代码中哪里可以找到.quad定义?

In 64 bit mode, gcc uses the LP64 convention. 在64位模式下,gcc使用LP64约定。 This means that long and pointers are 64 bits wide, but int is still only 32 bits wide. 这意味着long和指针的宽度为64位,而int仍然仅为32位。 In the expression 在表达中

  int test =(((0) & 0x00000000) << (32));

the constants are all assumed to be ints , because int is big enough to hold them all, and int s are always only 32 bits. ints假定为ints ,因为int足以容纳所有常量,并且int始终仅为32位。 The result of a shift >= width of the type is UB in C because the behaviour is generally dependent on the underlying architecture's shift instruction. 这种类型的移位> =宽度的结果是C中的UB,因为行为通常取决于基础体系结构的移位指令。

Suppress the warning by forcing one of the numbers to be 64 bit. 通过强制数字之一为64位来抑制警告。

long test =(((0) & 0x00000000L) << (32)); // Still gives a warning with -m32

or 要么

long long test =(((0) & 0x00000000LL) << (32)); // No warning, long long is always 64 bit

In C, the type of the left operand of the shift is int , which is 32-bit on both platforms in question, so the shift is always undefined behaviour in terms of the C language. 在C语言中,移位的左操作数的类型为int ,在上述两个平台上均为32位,因此就C语言而言,移位始终是未定义的行为。

I imagine that in your assembler the operand is either 32 or 64 bit, respectively. 我想象在您的汇编器中,操作数分别是32位或64位。

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

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