“f” after number

后端 未结 10 792
醉酒成梦
醉酒成梦 2020-11-27 11:02

What does the f after the numbers indicate? Is this from C or Objective-C? Is there any difference in not adding this to a constant number?

CGRec         


        
10条回答
  •  我在风中等你
    2020-11-27 11:49

    When in doubt check the assembler output. For instance write a small, minimal snippet ie like this

    #import 
    
    void test() {
      CGRect r = CGRectMake(0.0f, 0.0f, 320.0f, 50.0f);
      NSLog(@"%f", r.size.width);
    }
    

    Then compile it to assembler with the -S option.

    gcc -S test.m
    

    Save the assembler output in the test.s file and remove .0f from the constants and repeat the compile command. Then do a diff of the new test.s and previous one. Think that should show if there are any real differences. I think too many have a vision of what they think the compiler does, but at the end of the day one should know how to verify any theories.

提交回复
热议问题