简体   繁体   中英

error C2143: syntax error : missing ';' before 'type' when transferring pointer

I am confused by following error when I try to transfer the pointer to another one. Is there anybody can tell me why this error happen?

It says

error C2143: syntax error : missing ';' before 'type'

when transferring pointer as follow:

void compressString(char * pStr)
{
    char * pInputStr ;
    // ...
    pInputStr = pStr;  //**I can not understand why this sentence is error.** 
    // ...
}

But this one can work:

void compressString(char * pStr)
{
    char * pInputStr = pStr; //No error will be alerted. 
    // ...
}

This is more complete version of the function:

void compressString(char * pStr)
{

      char * pInputStr = pStr;  
      char * pCompressedStr = NULL;

      int  totalRepeatChar;  
      int currentPointerPosition; 
      int lenCompressedStr = 0;
      char testTemp;
      int i = 0;

      pInputStr = pStr;        //I can not understand why this sentence is error. 

      char arrIntCoverted[DIGITALUINTNUM+1] = {'\0'};

      // And then lots more code in the function
}

The error you get is because you mix declarations and executable statements, and Visual Studio uses an old C dialect where you can't do that.

This is an executable statement:

  pInputStr = pStr;        //I can not understand why this sentence is error. 

The error you get is not actually on that line, but on the next one, which is a declaration:

  char arrIntCoverted[DIGITALUINTNUM+1] = {'\0'};

In multiline comments "/" and "*" should be together. In your case you have new line at end of comment.

Check:

pInputStr = pStr;  //**I can not understand why this sentence is error.** 
    // ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM