Why am I getting a 'called object 0 is not a function error'?

后端 未结 4 532
庸人自扰
庸人自扰 2021-01-21 19:17

I\'m a C# developer trying to learn C (followed by C++). I am going native, working on Ubuntu using vim as my text editor, and the Gnu C Compiler (gcc) to compile.

I\'m

相关标签:
4条回答
  • 2021-01-21 20:07

    As people have pointed out

    int celcius = (5/9)(i-32);
    

    Should be

    int celcius = (5/9)*(i-32);
    

    However the reason you are getting that particular error message is that

    int celcius = (5/9)(i-32);
    

    is being evaluated at run time as

    int celcius = (0)(i-32);
    

    And the runtime system sees (0) as a pointer.

    So you need to change your math to avoid the integer division

    0 讨论(0)
  • 2021-01-21 20:13

    This line is problematic:

    int celcius = (5/9)(i-32);
    

    because the compiler thinks you're trying to invoke a function specified by (5/9). If you wished to do a multiplication, you should do:

    int celcius = (5/9)*(i-32);
    

    instead.

    Moreover, if you expect floating-point values to be returned from that calculation, you should do:

    int celcius = (5.0/9.0)*(i-32.0);
    

    because 5/9 is an integer division and will never return a floating-point value.

    0 讨论(0)
  • 2021-01-21 20:14

    In C (and I am assuming that in other languages too :)) an arithmetic operator is needed to perform an arithmetic operation.
    Change

    int celcius = (5/9)(i-32);
    

    to

    int celcius = (5/9)*(i-32);
    
    0 讨论(0)
  • 2021-01-21 20:14

    change

    int celcius = (5/9)(i-32)
    

    to

     int celcius = (5/9)*(i-32); 
    
    0 讨论(0)
提交回复
热议问题