MISRA C:2004年规则5.5(建议):不得重复使用具有静态存储期限的对象或功能标识符

时间:2019-02-06 14:43:35

标签: c misra

我有Understand SciTools发现的第二个违规,但是我没有明确纠正该违规的正确措施。

在以下代码中,违反行为以Rule 5.5 (advisory): No object or function identifier with static storage duration should be reused为准,尤其是Static Identifier 'x' reused

 /* llvalue -> ICmp.t option */
CAMLprim value llvm_instr_icmp_predicate(LLVMValueRef Val) {
  CAMLparam0();
  int x = LLVMGetICmpPredicate(Val);
  if (x) {
    value Option = alloc(1, 0);
    Field(Option, 0) = Val_int(x - LLVMIntEQ);
    CAMLreturn(Option);
  }
  CAMLreturn(Val_int(0));
}

/* llvalue -> FCmp.t option */
CAMLprim value llvm_instr_fcmp_predicate(LLVMValueRef Val) {
  CAMLparam0();
  int x = LLVMGetFCmpPredicate(Val);
  if (x) {
    value Option = alloc(1, 0);
    Field(Option, 0) = Val_int(x - LLVMRealPredicateFalse);
    CAMLreturn(Option);
  }
  CAMLreturn(Val_int(0));
}

1 个答案:

答案 0 :(得分:4)

在项目中的某个地方,您还有另一个名为 RecyclerView CategoriesRecyclerView; RecyclerView.LayoutManager CategoriesLayoutManager; CategoriesAdapter CategoriesAdapter; List<Category> categories; protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Get our RecyclerView layout: CategoriesRecyclerView = FindViewById<RecyclerView>(Resource.Id.CategoriesRecyclerView); //............................................................ // Layout Manager Setup: // Use the built-in linear layout manager: CategoriesLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.Horizontal, true); // Plug the layout manager into the RecyclerView: CategoriesRecyclerView.SetLayoutManager(CategoriesLayoutManager); //............................................................ // Adapter Setup: CategoriesAdapter = new CategoriesAdapter(categories); // Register the item click handler (below) with the adapter: CategoriesAdapter.ItemClick += CategoriesOnItemClick; // Plug the adapter into the RecyclerView: CategoriesRecyclerView.SetAdapter(CategoriesAdapter); } void CategoriesOnItemClick(object sender, int position) { //here I want the reference to the textview // ((TextView).SetBackgroundColor(Color.Aqua); Toast.MakeText(this, "This is category " + categories[position].Id + categories[position].Name, ToastLength.Short).Show(); } 的变量,具有静态存储持续时间。不一定与您违反MISRA的翻译机构相同。

这始终是一个愚蠢的规则,我会在整个组织范围内创建一个永久偏差并忽略它。 (这是一个咨询规则)

另一方面,x是一个可怕的变量名。