Inconsistent results from printf with long long int?

前端 未结 4 1573
花落未央
花落未央 2021-01-16 07:59
struct DummyStruct{
        unsigned long long std;
        int type;
};

DummyStruct d;
d.std = 100;
d.type = 10;

/// buggy printf, unsigned long long to int conve         


        
4条回答
  •  借酒劲吻你
    2021-01-16 08:18

    With printf (which is one of the very old functions from original C) the compiler does not cast the paramters after the format list to the desired type, i.e. you need to make sure yourself that the types in the parameter list match the one in the format.

    With most other functions, the compiler squeezes the given parameter into the declared types, but printf, scanf and friends require you to tell the compiler exactly which types are following.

提交回复
热议问题