gcc optimization? bug? and its practial implication to project

前端 未结 5 1453
谎友^
谎友^ 2021-01-11 16:11

My questions are divided into three parts

Question 1
Consider the below code,

#include 
using namespace std;

i         


        
5条回答
  •  情深已故
    2021-01-11 16:39

    Q1: Perhaps, the number is indeed positive in a 64bit implementation? Who knows? Before debugging the code I'd just printf("%d", i+v);

    Q2: The parentheses are only there to tell the compiler how to parse an expression. This is usually done in the form of a tree, so the optimizer does not see any parentheses at all. And it is free to transform the expression.

    Q3: That's why, as c/c++ programmer, you must not write code that assumes particular properties of the underlying hardware, such as, for example, that an int is a 32 bit quantity in two's complement form.

提交回复
热议问题