C - expected expression before '=' token… on line without '='

心已入冬 提交于 2020-01-03 07:30:53

问题


I'm going crazy trying to figure out this error message that has no obvious connection to reality/my code. I've been searching on here and come to one conclusion: you're going to hate the pointer hidden by typedef. Sorry, it's out of my control--prof provided the code that way. I'm editing the code as specified in the problem. I'm popping full nodes to avoid malloc calls on each push function and storing them in a secondary stack. The MakeEmptyS function initializes a Stack with INITIAL_SIZE nodes. GrowEmptyS adds more nodes to the Stack of empty nodes

stack.c has the following function:

void
MakeEmptyS( Stack S )
{
  PtrToNode tmp;
  if ( S == NULL )
    Error( "Must use CreateStack first" );
  else
  {
    GrowEmptyS( S, INITIAL_SIZE);
    while (!IsEmptyS( S) )
    {
        tmp = TopopNode( S );
        PushEmpty( S, tmp);
    }
  }
}

I get this error: "Stack.c:53:22: error: expected expression before '=' token", where line 53 is GrowEmptyS( S, INITIAL_SIZE );

For reference, here is the Grow function:

   void
   GrowEmptyS( Stack S, int NumToAdd )
   {
       int i;
       PtrToNode TmpCell;
       for( i = 0; i < NumToAdd; i++ )
       {
         TmpCell = malloc( sizeof(struct Node));
         if ( TmpCell == NULL )
           FatalError( "Out of Space!!!");
         else
           PushEmpty(S,TmpCell);
       }
   }

回答1:


I may be wrong but probably you defined

#define INITIAL_SIZE = 1024

for example.

You should remove the =.

The correct definition would be

#define INITIAL_SIZE 1024

As an advice, function parameters should start with lower case, not upper case :)

void GrowEmptyS(Stack stack, int numToAdd)

is easier to read.



来源:https://stackoverflow.com/questions/7942837/c-expected-expression-before-token-on-line-without

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!