C - expected expression before '=' token…

2019-06-16 06:31发布

问题:

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.