C语言 C 编程,错误:被调用的对象不是函数或函数指针

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26780011/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 11:32:04  来源:igfitidea点击:

C programming, error: called object is not a function or function pointer

ccompiler-errorsfunction-pointers

提问by Freddie Chopin

I am trying to write a program which implements the Pop and Push functions. The problem is, I am trying to pass the pointer that points to integer Top to the function, so that this integer keeps changing, but when I try to compile I always get this line:

我正在尝试编写一个实现 Pop 和 Push 功能的程序。问题是,我试图将指向整数 Top 的指针传递给函数,以便这个整数不断变化,但是当我尝试编译时,我总是得到这一行:

**error: called object is not a function or function pointer (*t)--

**错误:被调用的对象不是函数或函数指针 (*t)--

#include<stdio.h>
#include<stdlib.h>

#define MAX 10
int push(int stac[], int *v, int *t)
{
  if((*t) == MAX-1)
  {
      return(0);
  }
  else
  {
      (*t)++;
      stac[*t] = *v;
      return *v;
   }
}

int pop(int stac[], int *t)
{
 int popped;
 if((*t) == -1)
 {
      return(0);
 }
 else
 {
     popped = stac[*t]
     (*t)--;
     return popped;
 } 
}
int main()
{
int stack[MAX];
int value;
int choice;
int decision;
int top;
top = -1;
do{
   printf("Enter 1 to push the value\n");
   printf("Enter 2 to pop the value\n");
   printf("Enter 3 to exit\n");
   scanf("%d", &choice);
   if(choice == 1)
   {
       printf("Enter the value to be pushed\n");
       scanf("%d", &value);
       decision = push(stack, &value, &top);
       if(decision == 0)
       { 
           printf("Sorry, but the stack is full\n");  
       }
       else
       {
           printf("The value which is pushed is: %d\n", decision);
       }
   }
   else if(choice == 2)
    {
         decision = pop(stack, &top);
        if(decision == 0)
          {
               printf("The stack is empty\n");
          }
         else
          {
              printf("The value which is popped is: %d\n", decision);
          }

    }
 }while(choice != 3);
 printf("Top is %d\n", top);

}

回答by Freddie Chopin

You missed one semicolon just before that line with error:

您在该行之前错过了一个分号并出现错误:

 poped = stac[*t] <----- here
 (*t)--;

The reason for this strange error is that compiler saw sth like that:

这个奇怪错误的原因是编译器看到了这样的东西:

 poped = stac[*t](*t)--;

Which it could interpret as a call to a function pointer coming from a table, but this obviously makes no sense, because stac is an array of ints, not an array of function pointers.

它可以解释为对来自表的函数指针的调用,但这显然没有意义,因为 stac 是一个整数数组,而不是一个函数指针数组。