在线求帮助initialization of 'q' is skipped by 'goto SERVER_S

C++语言 码拜 8年前 (2016-04-24) 927次浏览
  char p = 0; 
  char* q = (char*)lpShareMemory; 
  do 
  { 
    p = getchar(); 
    if (WaitForSingleObject(hClientReadOver, 5*1000) != WAIT_OBJECT_0)  
      goto SERVER_SHARE_MEMORY_END; 
    q[0] = p; 
    if (!ResetEvent(hClientReadOver)) goto SERVER_SHARE_MEMORY_END;//把指定的事件对象设置为无信号状态 
    if (!SetEvent(hServerWriteOver)) goto SERVER_SHARE_MEMORY_END;//把指定的事件对象设置为有信号状态 
  } while (p != "\n"); 
  
SERVER_SHARE_MEMORY_END: //错误指向这里
  //释放共享内存 
  if (NULL != hServerWriteOver)  CloseHandle(hServerWriteOver); 
  if (NULL != hClientReadOver)  CloseHandle(hClientReadOver); 
  if (NULL != lpShareMemory)   UnmapViewOfFile(lpShareMemory); 
  if (NULL != hFileMapping)    CloseHandle(hFileMapping); 
  if (NULL != hMutex)       ReleaseMutex(hMutex); 
  return 0;

错误提示本人看q的声明.本人看不出哪里有问题…
错误提示:initialization of “q” is skipped by “goto SERVER_SHARE_MEMORY_END”
: see declaration of “q”

解决方案

40

引用:
Quote: 引用:

题主前面是不是还有goto SERVER_SHARE_MEMORY_END;
定义不可以被goto跨,你的q被goto跨了
不妨用if else替代掉goto

在代码上要怎么修改。本人修改了一下还是报错。不知道是不是本人修改错了

把本人声明在goto的前面

40

不是深层嵌套的话不必用goto
http://blog.csdn.net/hitlion2008/article/details/6844615

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明在线求帮助initialization of 'q' is skipped by 'goto SERVER_S
喜欢 (0)
[1034331897@qq.com]
分享 (0)