volatile variables as argument to function

前端 未结 5 1541
天命终不由人
天命终不由人 2020-12-09 12:58

Having this code:

typedef volatile int COUNT;       

COUNT functionOne( COUNT *number );

int  functionTwo( int *number );

I can\'t get ri

5条回答
  •  执念已碎
    2020-12-09 13:22

    I don't understand why you'd want to have the volatile qualifier on a function return type. The variable that you assign the function's return value to should be typed as a volatile instead.

    Try making these changes:

    typedef int COUNT_TYPE;
    typedef volatile COUNT_TYPE COUNT;       
    
    COUNT_TYPE functionOne( COUNT number );
    
    COUNT_TYPE functionTwo( COUNT_TYPE number );
    

    And when calling functionTwo(), explicitly cast the argument:

    functionTwo( (COUNT_TYPE)arg );
    

    HTH, Ashish.

提交回复
热议问题