在VC6中运行以下代码
////////////////////////////////
//main.c
#include <stdio.h>
int main()
{
char a[100];
memset(&a, 0, 100);
char b;
return 0;
}
/////////////////////////////////
编译器将会报一个编译错误,
syntax error : missing ';' before 'type'
这个错误出在
char b;
这一行。
然后将程序改为
////////////////////////////////
//main.c
#include <stdio.h>
int main()
{
char a[100];
char b;
memset(&a, 0, 100);
return 0;
}
/////////////////////////////////
程序就会顺利通过编译。
经过测试发现
在VC中编译c程序,在一个大括号括起的范围内,如果变量声明放在了函数调用的后面,那么编译的时候就会报错:
syntax error : missing ';' before 'type'
然后你可以修改为把变量声明放在函数调用之前。就会顺利通过编译。
这个问题在vc编译c++程序,或者gcc编译c程序的时候都不会出现,仅仅在vc编译c程序的时候才会出现.
----------------------------------------------------------------------------------------------------------
bool SelectFile(OPENFILENAMEEX *ofn)
{
TCHAR szFile[MAX_PATH];
ofn->lStructSize = sizeof(OPENFILENAMEEX);
ofn->lpstrFilter = _T("All Files (*.*)/0*.*/0");
ofn->lpstrFile = szFile;
ofn->nMaxFile = sizeof(szFile)/sizeof(szFile[0]);
ofn->lpstrInitialDir = _T("//Program Files"); // 这里可以指定打开的默认目录
ofn->lpstrTitle = _T("Select a Zip");
ofn->ExFlags = OFN_EXFLAG_THUMBNAILVIEW | OFN_EXFLAG_HIDEDRMPROTECTED;
return GetOpenFileNameEx(ofn);
}
int SelFolder(HWND hParent, wstring &str)
{
InitCommonControls();
LPMALLOC lpMalloc;
::SHGetMalloc(&lpMalloc);
BROWSEINFO bi;
char name[MAX_PATH];
ZeroMemory(&bi,sizeof(BROWSEINFO));
bi.hwndOwner = hParent;
bi.pszDisplayName = name;
bi.lpszTitle = LPCSTR(TEXT("Select folder"));
bi.ulFlags = BIF_RETURNFSANCESTORS|BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = 0;
LPITEMIDLIST idl = SHBrowseForFolder(&bi);
if(idl == NULL)
return 0;
return SHGetPathFromIDList(idl, LPTSTR(str.data()));
}
void OnBrower()
{
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = L"Open";
ShExecInfo.lpFile = L"fexplore.exe";
ShExecInfo.lpParameters = L"//Program Files";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
}
-----------------------------------------------------------------------------------------------------------------
e(E1|E2|E3)的实现:
#include <stdio.h> #include <iostream> using namespace std; #define E1 0x01 #define E2 0x02 #define E3 0x04 #define E4 0x08 void e(int type) { if((type & E1) == E1) { cout<< "E1" <<endl; } if((type & E2) == E2) { cout<< "E2" <<endl; } if((type & E3) == E3) { cout<< "E3" <<endl; } if((type & E4) == E4) { cout<< "E4" <<endl; } } int main(int argc, char *argv[]) { e(E1|E2|E3); return 0; }